Prestashop:具有多字段的HelperForm

时间:2017-04-12 19:00:25

标签: prestashop prestashop-1.6

我使用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));

我在后台看不到“名称”字段。怎么了?如果我删除'lang'=>它出现了。 是否需要任何其他设置(如在构造函数中)?

1 个答案:

答案 0 :(得分:0)

这是标准的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数组和id_language中的'语言'。

也许这个link应该会有所帮助。