Anton Qcl Posted September 7, 2013 Report Posted September 7, 2013 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.phpPrinting 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} Quote
Tyson Posted September 7, 2013 Report Posted September 7, 2013 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. Quote
Anton Qcl Posted September 7, 2013 Author Report Posted September 7, 2013 Thank you for answer but no, I don't want add row. Method addModuleRow() work correct in my modules.I wish to add setting which will be act for entire module, not for one row. Quote
Tyson Posted September 7, 2013 Report Posted September 7, 2013 Where in your module are you attempting to set meta data? Quote
Anton Qcl Posted September 7, 2013 Author Report Posted September 7, 2013 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. Quote
Tyson Posted September 7, 2013 Report Posted September 7, 2013 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(); } Quote
Anton Qcl Posted September 8, 2013 Author Report Posted September 8, 2013 Ok, it works, thank you! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.