Jump to content

Recommended Posts

Posted

Hello, I have a problem with save field of my module settings.

Version: 3.0.2

URL: /admin/settings/company/modules/manage/3/

Action: Press button "Save" in my custom module.

 


Code of my "manageModule" method:

 

















public function manageModule($module, array &$vars) {
$this->view = new View("manage", "default");
$this->view->base_uri = $this->base_uri;
$this->view->setDefaultView("components" . DS . "modules" . DS . "vs_manager" . DS);

Loader::loadHelpers($this, array("Form", "Html", "Widget"));
$this->view->set("module", $module);

return $this->view->fetch();
}


Code of my manage.pdt:

















<?php $this->Widget->clear(); ?>
<?php $this->Widget->create($this->_("AdminCompanyModules.manage.boxtitle_manage", true, $this->Html->_($module->name, true))); ?>
<?php $this->Form->create(); ?>
    <div class="title_row first">
        <div class="pad">
            <?php $this->Form->label("Settings", "my_settings"); ?>
            <?php $this->Form->fieldText("settings", $this->Html->ifSet($module->meta->settings), array('id'=>"my_settings")); ?>
        </div>
        <div class="button_row">
            <a href="#" class="btn_right submit">Save</a>
        </div>
    </div>
<?php $this->Form->end(); ?>
<?php $this->Widget->end();?>

 


I've expected that data will be saved but I've got next error:

 

SQLSTATE[HY000]: General error: 1364 Field 'key' doesn't have a default value on line 124 in /var/www/my.blesta.site/public_html/lib/model.php

Printing Stack Trace:
#0 /var/www/my.blesta.site/public_html/lib/model.php(124): PDOStatement->execute(Array)
#1 /var/www/my.blesta.site/public_html/components/record/record.php(215): Model->query('INSERT INTO `mo...', Array)
#2 /var/www/my.blesta.site/public_html/app/models/module_manager.php(390): Record->insert('module_meta', Array, Array)
#3 /var/www/my.blesta.site/public_html/app/controllers/admin_company_modules.php(75): ModuleManager->setMeta('3', Array)
#4 /var/www/my.blesta.site/public_html/lib/dispatcher.php(111): AdminCompanyModules->manage()
#5 /var/www/my.blesta.site/public_html/index.php(21): Dispatcher::dispatch('/admin/settings...')
#6 {main}

Posted

You need to look at your addModuleRow() method, as this is the method that actually creates new module rows, which I think is what you're trying to do here. It will help to review the module documentation.

 

I've also moved this thread to the Extensions forums because this issue is a problem with your module's implementation--not a bug with Blesta.

Posted

I am creating field for show and edit module-meta-settings in manage.pdt.
Full test code is in my first post.
I expect that when I press button "Save" on /admin/settings/company/modules/manage/3/ data will be saved in table "modue_meta".

This data will be displayed to user(administrator) when he will be on url /admin/settings/company/modules/manage/3/ again.

 

This doesn't happens because the /var/www/my.blesta.site/public_html/app/controllers/admin_company_modules.php receive empty array "POST"($this->post) but have to receive array "POST"($this->post) with data from my form. 

Posted

Similar to addModuleRow(), you need to format the post data, do any validation checks, etc.

 

e.g.

	public function manageModule($module, array &$vars) {
		// Load the view into this object, so helpers can be automatically added to the view
		$this->view = new View("manage", "default");
		$this->view->base_uri = $this->base_uri;
		$this->view->setDefaultView("components" . DS . "modules" . DS . "vs_manager" . DS);
		
		$meta_fields = array("settings");
		$encrypted_fields = array();
		
		$rules = array(
			'settings' => array(
				'empty' => array(
					'rule' => "isEmpty",
					'negate' => true,
					'message' => "Please enter settings."
				)
			)
		);
		$this->Input->setRules($rules);
		
		// Validate module meta
		if ($this->Input->validates($vars)) {

			// Build the meta data
			$meta = array();
			foreach ($vars as $key => $value) {
				
				if (in_array($key, $meta_fields)) {
					$meta[] = array(
						'key'=>$key,
						'value'=>$value,
						'encrypted'=>in_array($key, $encrypted_fields) ? 1 : 0
					);
				}
			}
			
			$vars = $meta;
		}
		
		// Load the helpers required for this view
		Loader::loadHelpers($this, array("Form", "Html", "Widget"));
		
		$this->view->set("module", $module);
		
		return $this->view->fetch();
	}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...