OpenCart 2.3.0.2 无法保存自定义模块设置
OpenCart 2.3.0.2 Can not save custom module settings
我在我的模块的管理部分遇到了这个问题。我的 OpenCart 版本:2.3.0.2。
问题出在哪里?
admin/controller/extension/module/mymodule.php
<?php
class ControllerExtensionModuleMyModule extends Controller {
private $error = array();
public function index() {
$this->load->language('extension/module/mymodule');
$this->load->model('setting/setting');
$this->document->setTitle($this->language->get('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('mymodule', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['entry_text'] = $this->language->get('entry_text');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/mymodule', 'token=' . $this->session->data['token'], true)
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/mymodule', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true)
);
}
$data['action'] = $this->url->link('extension/module/mymodule', 'token=' . $this->session->data['token'], true);
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true);
if (isset($this->request->post['text_example'])) {
$data['text_example'] = $this->request->post['text_example'];
} else {
$data['text_example'] = $this->config->get('text_example');
}
$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('extension/module/mymodule', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/mymodule')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
admin/view/template/extension/module/mymodule.tpl
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-mymodule" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a>
</div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-mymodule" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-text-example"><?php echo $entry_text; ?></label>
<div class="col-sm-10">
<input type="text" name="text_example" value="<?php echo $text_example; ?>" placeholder="<?php echo $text_example; ?>" id="input-text-example" class="form-control" />
</div>
</div>
</form>
</div>
</div>
</div>
admin/language/en-gb/extension/module/mymodule.php
<?php
// Heading
$_['heading_title'] = 'My Module';
// Text
$_['text_extension'] = 'Extensions';
$_['text_success'] = 'Success: You have modified My module!';
$_['text_edit'] = 'Edit My Module';
// Entry
$_['entry_text'] = 'text';
// Error
$_['error_permission'] = 'Warning: You do not have permission to modify My module!';
error.log = 空。
问题出在您的命名约定中。您应该使用 modulename_input
作为表单中的输入字段。你可以这样做。
1.Change 控制器中的代码
if (isset($this->request->post['mymodule_text_example'])) {
$data['text_example'] = $this->request->post['mymodule_text_example'];
} else {
$data['text_example'] = $this->config->get('mymodule_text_example');
}
2.And 在您的相关视图文件中
<input type="text" name="mymodule_text_example" value="<?php echo $text_example; ?>" placeholder="<?php echo $text_example; ?>" id="input-text-example" class="form-control" />
希望它能完美运行。试试这个。
mymodule.php
if (isset($this->request->post['mymodule_text_example'])) {
$data['mymodule_text_example'] = $this->request->post['mymodule_text_example'];
} else {
$data['mymodule_text_example'] = $this->config->get('mymodule_text_example');
}
mymodule.tpl
<input type="text" name="mymodule_text_example" value="<?php echo $mymodule_text_example; ?>" placeholder="<?php echo $mymodule_text_example; ?>" id="input-text-example" class="form-control" />
我在我的模块的管理部分遇到了这个问题。我的 OpenCart 版本:2.3.0.2。 问题出在哪里?
admin/controller/extension/module/mymodule.php
<?php
class ControllerExtensionModuleMyModule extends Controller {
private $error = array();
public function index() {
$this->load->language('extension/module/mymodule');
$this->load->model('setting/setting');
$this->document->setTitle($this->language->get('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('mymodule', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['entry_text'] = $this->language->get('entry_text');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true)
);
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/mymodule', 'token=' . $this->session->data['token'], true)
);
} else {
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/module/mymodule', 'token=' . $this->session->data['token'] . '&module_id=' . $this->request->get['module_id'], true)
);
}
$data['action'] = $this->url->link('extension/module/mymodule', 'token=' . $this->session->data['token'], true);
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=module', true);
if (isset($this->request->post['text_example'])) {
$data['text_example'] = $this->request->post['text_example'];
} else {
$data['text_example'] = $this->config->get('text_example');
}
$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('extension/module/mymodule', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/module/mymodule')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
admin/view/template/extension/module/mymodule.tpl
<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
<div class="page-header">
<div class="container-fluid">
<div class="pull-right">
<button type="submit" form="form-mymodule" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
<a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a>
</div>
<h1><?php echo $heading_title; ?></h1>
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<div class="container-fluid">
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
<?php } ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
</div>
<div class="panel-body">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-mymodule" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-text-example"><?php echo $entry_text; ?></label>
<div class="col-sm-10">
<input type="text" name="text_example" value="<?php echo $text_example; ?>" placeholder="<?php echo $text_example; ?>" id="input-text-example" class="form-control" />
</div>
</div>
</form>
</div>
</div>
</div>
admin/language/en-gb/extension/module/mymodule.php
<?php
// Heading
$_['heading_title'] = 'My Module';
// Text
$_['text_extension'] = 'Extensions';
$_['text_success'] = 'Success: You have modified My module!';
$_['text_edit'] = 'Edit My Module';
// Entry
$_['entry_text'] = 'text';
// Error
$_['error_permission'] = 'Warning: You do not have permission to modify My module!';
error.log = 空。
问题出在您的命名约定中。您应该使用 modulename_input
作为表单中的输入字段。你可以这样做。
1.Change 控制器中的代码
if (isset($this->request->post['mymodule_text_example'])) {
$data['text_example'] = $this->request->post['mymodule_text_example'];
} else {
$data['text_example'] = $this->config->get('mymodule_text_example');
}
2.And 在您的相关视图文件中
<input type="text" name="mymodule_text_example" value="<?php echo $text_example; ?>" placeholder="<?php echo $text_example; ?>" id="input-text-example" class="form-control" />
希望它能完美运行。试试这个。
mymodule.php
if (isset($this->request->post['mymodule_text_example'])) {
$data['mymodule_text_example'] = $this->request->post['mymodule_text_example'];
} else {
$data['mymodule_text_example'] = $this->config->get('mymodule_text_example');
}
mymodule.tpl
<input type="text" name="mymodule_text_example" value="<?php echo $mymodule_text_example; ?>" placeholder="<?php echo $mymodule_text_example; ?>" id="input-text-example" class="form-control" />