php - Edit value to database through custom admin, Opencart 2.0 -
i trying make easy form in opencart 2.0.1.1 stores values in database.
i have done custom admin page have extensions make of own. easy part.
i have made form , column in database, working fine, values , showing in textarea inside admin. issue when trying edit texts. when change value of textarea , hit save dissapears! , column in database gone.
my controller file:
admin/controller/ekomet/design.php
<?phpclass controllerekometdesign extends controller { private $error = array(); public function index() { $this->load->language('ekomet/design'); $this->document->settitle($this->language->get('heading_title')); $this->load->model('setting/setting'); if (($this->request->server['request_method'] == 'post') && $this->validate()) { $this->model_setting_setting->editsetting('design_name', $this->request->post); } $data['button_save'] = $this->language->get('button_save'); $data['button_cancel'] = $this->language->get('button_cancel'); $data['tab_general'] = $this->language->get('tab_general'); $data['breadcrumbs'] = array(); $data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'ssl') ); $data['breadcrumbs'][] = array( 'text' => $this->language->get('text_stores'), 'href' => $this->url->link('ekomet/design', 'token=' . $this->session->data['token'], 'ssl') ); $data['breadcrumbs'][] = array( 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('ekomet/design', 'token=' . $this->session->data['token'], 'ssl') ); if (isset($this->session->data['success'])) { $data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $data['success'] = ''; } $data['action'] = $this->url->link('ekomet/design', 'token=' . $this->session->data['token'], 'ssl'); $data['cancel'] = $this->url->link('ekomet/design', 'token=' . $this->session->data['token'], 'ssl'); $data['token'] = $this->session->data['token']; $settings = $this->model_setting_setting->getsetting('design_name'); if (isset($this->request->post['config_ekomet_name'])) { $data['config_ekomet_name'] = $this->request->post['config_ekomet_name']; } else { $data['config_ekomet_name'] = $this->config->get('config_ekomet_name'); } $data['header'] = $this->load->controller('common/header'); $data['column_left'] = $this->load->controller('common/column_left'); $data['footer'] = $this->load->controller('common/footer'); $this->response->setoutput($this->load->view('ekomet/design.tpl', $data)); } protected function validate() { if (!$this->user->haspermission('modify', 'ekomet/design')) { $this->error['warning'] = $this->language->get('error_permission'); } if ($this->error && !isset($this->error['warning'])) { $this->error['warning'] = $this->language->get('error_warning'); } return !$this->error; }}
i have looked through setting.php controller , want use setting table in database store values (no need invent wheel again). said above. pass values database. can't update it.
my template file:
admin/view/template/ekomet/design.tpl
<div class="form-group required"> <label class="col-sm-2 control-label" for="input-ekomet-name">e-komet namn</label> <div class="col-sm-10"> <input type="text" name="config_ekomet_name" value="<?php echo $config_ekomet_name; ?>" placeholder="<?php echo $entry_ekomet_name; ?>" id="input-ekomet-name" class="form-control" /> <?php if ($error_ekomet_name) { ?> <div class="text-danger"><?php echo $error_ekomet_name; ?></div> <?php } ?> </div> </div>
i have not made own model file because want use 1 connected setting. need make own model make work?
you using wrong prefix code , key field
make sure if code = abc
key = abc_def
replace
$this->model_setting_setting->editsetting('design_name', $this->request->post);
with
$this->model_setting_setting->editsetting('config', $this->request->post);
so code = config
, key = config_ekomet_name
Comments
Post a Comment