我已经创建了一个自定义模块:
模块/ MyModule的/ mymodule.php
<?php
if (!defined('_PS_VERSION_'))
exit;
class mymodule extends Module
{
public function __construct()
{
$this->name = 'mymodule';
$this->tab = 'quick_bulk_update';
$this->version = '1.0.0';
$this->author = 'MYMODULE';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('MYMODULE');
$this->description = $this->l('MYMODULE DESCRIPTION');
$this->confirmUninstall = $this->l('¿Está seguro de desinstalar este módulo?');
if (!Configuration::get('mymodule'))
$this->warning = $this->l('No se ha introducido ningún nombre');
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
if (!parent::install() || !Configuration::updateValue('mymodule', 'mymodule'))
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall() ||
!Configuration::deleteByName('mymodule')
)
return false;
return true;
}
public function getContent()
{
$output = null;
if (Tools::isSubmit('submit'.$this->name))
{
$my_module_name = strval(Tools::getValue('mymodule'));
if (!$my_module_name
|| empty($my_module_name)
|| !Validate::isGenericName($my_module_name))
$output .= $this->displayError($this->l('Valor de configuración incorrecto'));
else
{
Configuration::updateValue('mymodule', $my_module_name);
$output .= $this->displayConfirmation($this->l('Ajustes actualizados correctamente'));
}
}
return $output.$this->displayForm();
}
public function displayForm()
{
// Get default language
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
// Init Fields form array
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Ajustes'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Valor de configuración'),
'name' => 'mymodule',
'size' => 20,
'required' => true
)
),
'submit' => array(
'title' => $this->l('Guardar'),
'class' => 'button'
)
);
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true; // false -> remove toolbar
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = array(
'save' =>
array(
'desc' => $this->l('Guardar'),
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value['mymodule'] = Configuration::get('mymodule');
return $helper->generateForm($fields_form);
}
}
我在后端添加了一个标签,也用于配置值。我通过管理员&gt;做到了后端选项菜单。我之前创建了下一个文件:
模块/ MyModule的/控制器/管理/ AdminMyModule.php
<?php
class AdminMyModuleController extends ModuleAdminController {
public function __construct(){
}
}
名为mymodule的选项卡正确显示在后端菜单中,但是当我选择它时,加载的页面不会显示任何内容。 我需要在上面显示displayForm函数的形式。当我转到模块时,会显示此表单&gt; mymodule&gt;组态。此表单在ps_configuration表中保存值。 实际上,我只需要这个表单,在配置表中保存一些值,等等。
答案 0 :(得分:0)
最后我以这种方式解决了它:
class AdminMyModuleController extends ModuleAdminController {
public function __construct()
{
$this->bootstrap = true;
$this->className = 'Configuration';
$this->table = 'configuration';
parent::__construct();
$this->fields_options = array(
'general' => array(
'title' => $this->l('Ajustes para configurar mi modulo'),
'fields' => array(
'MYMODULE_IDCLIENTE' => array(
'title' => $this->l('Identificador de cliente'),
'type' => 'text',
'size' => 20,
'required' => true
),
'MYMODULE_EXECUTION_INTERVAL_UNIT' => array(
'title' => $this->l('Intervalo de ejecución (unidad)'),
'type' => 'select',
'size' => 5,
'required' => true,
'identifier' => "execution_interval_unit",
"desc" => "Indique si desea que la sincronización se realice cada x minutos, horas, días, semanas o meses.",
'list' => array(
array( "execution_interval_unit" => "1", "name" => 'Minutos' ),
array( "execution_interval_unit" => "2", "name" => 'Horas' ),
array( "execution_interval_unit" => "3", "name" => 'Días' ),
array( "execution_interval_unit" => "4", "name" => 'Semanas' ),
array( "execution_interval_unit" => "5", "name" => 'Meses' )
)
),
'MYMODULE_EXECUTION_INTERVAL_VALUE' => array(
'title' => $this->l('Intervalo de ejecución (valor)'),
'type' => 'text',
'size' => 20,
'required' => true
),
),
'submit' => array('title' => $this->l('Save'))
),
);
}
}
希望这对其他人有所帮助。 问候,