Prestashop:具有多语言字段的 HelperForm
Prestashop: HelperForm with multilang field
我在哪里使用 Helperform。我想让一些字段可以翻译。我添加了以下表格:
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Diplom hinzufügen'),
'icon' => 'icon-question'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'lang' => true,
),
),
'submit' => array('title' => $this->l('Save'))
)
);
$helper = new HelperForm();
$helper->submit_action = 'saveDiplom';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => array(
'name' => '',
),
);
return $helper->generateForm(array($fields_form));
我在后台没有看到 "name" 字段。怎么了?如果我删除 'lang' => true 它就会出现。
是否需要任何其他设置(如在构造函数中)?
这是一个标准的 HelperForm 初始化:
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitNameOfModuleModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
. '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs, in your case you have passed the array directly */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
我猜你忘记了 tpl_vars
数组中的 'languages' 和 id_language
。
也许这个 link 应该有用。
我在哪里使用 Helperform。我想让一些字段可以翻译。我添加了以下表格:
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Diplom hinzufügen'),
'icon' => 'icon-question'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'lang' => true,
),
),
'submit' => array('title' => $this->l('Save'))
)
);
$helper = new HelperForm();
$helper->submit_action = 'saveDiplom';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => array(
'name' => '',
),
);
return $helper->generateForm(array($fields_form));
我在后台没有看到 "name" 字段。怎么了?如果我删除 'lang' => true 它就会出现。 是否需要任何其他设置(如在构造函数中)?
这是一个标准的 HelperForm 初始化:
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitNameOfModuleModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
. '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs, in your case you have passed the array directly */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
我猜你忘记了 tpl_vars
数组中的 'languages' 和 id_language
。
也许这个 link 应该有用。