Prestashop 1.6 Module error: Notice on line 719 in file prestashop16\tools\smarty\sysplugins\smarty_internal_templatebase.php

Prestashop 1.6 Module error: Notice on line 719 in file prestashop16\tools\smarty\sysplugins\smarty_internal_templatebase.php

我正在开发一个模块并扩展 AdminFeaturesController.php 以显示我的自定义字段 Add/Edit 特征值,但它在弹出窗口中显示以下错误:

Notice on line 719 in file D:\xampp\htdocs\prestashop16\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code [8] Undefined index: value

我认为这是因为我覆盖了 AdminFeaturesController.php 文件中的函数 initFormFeatureValue() 并添加了一个新字段。这是相关代码:

public function initFormFeatureValue()
    {
        $this->setTypeValue();

        $this->fields_form[0]['form'] = array(
            'legend' => array(
                'title' => $this->l('Feature value'),
                'icon' => 'icon-info-sign'
            ),
            'input' => array(
                array(
                    'type' => 'select',
                    'label' => $this->l('Feature'),
                    'name' => 'id_feature',
                    'options' => array(
                        'query' => Feature::getFeatures($this->context->language->id),
                        'id' => 'id_feature',
                        'name' => 'name'
                    ),
                    'required' => true
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Value'),
                    'name' => 'value',
                    'lang' => true,
                    'size' => 33,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
                    'required' => true
                ),
                array(
                    'type' => 'select',
                    'label' => $this->l('Parent Feature Value'),
                    'name' => 'parent_id_feature_value',
                    'options' => array(
                        'query' => FeatureValue::getFeatureValues((int)Tools::getValue('id_feature')),
                        'id' => 'id_feature_value',
                        'name' => 'value'
                    ),
                    'required' => true
                ),
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            ),
            'buttons' => array(
                'save-and-stay' => array(
                    'title' => $this->l('Save then add another value mamu'),
                    'name' => 'submitAdd'.$this->table.'AndStay',
                    'type' => 'submit',
                    'class' => 'btn btn-default pull-right',
                    'icon' => 'process-icon-save'
                )
            )
        );

        $this->fields_value['id_feature'] = (int)Tools::getValue('id_feature');

        // Create Object FeatureValue
        $feature_value = new FeatureValue(Tools::getValue('id_feature_value'));

        $this->tpl_vars = array(
            'feature_value' => $feature_value,
        );

        $this->getlanguages();
        $helper = new HelperForm();
        $helper->show_cancel_button = true;

        $back = Tools::safeOutput(Tools::getValue('back', ''));
        if (empty($back))
            $back = self::$currentIndex.'&token='.$this->token;
        if (!Validate::isCleanHtml($back))
            die(Tools::displayError());

        $helper->back_url = $back;
        $helper->currentIndex = self::$currentIndex;
        $helper->token = $this->token;
        $helper->table = $this->table;
        $helper->identifier = $this->identifier;
        $helper->override_folder = 'feature_value/';
        $helper->id = $feature_value->id;
        $helper->toolbar_scroll = false;
        $helper->tpl_vars = $this->tpl_vars;
        $helper->languages = $this->_languages;
        $helper->default_form_language = $this->default_form_language;
        $helper->allow_employee_form_lang = $this->allow_employee_form_lang;
        $helper->fields_value = $this->getFieldsValue($feature_value);
        $helper->toolbar_btn = $this->toolbar_btn;
        $helper->title = $this->l('Add a new feature value');
        $this->content .= $helper->generateForm($this->fields_form);
    }

知道为什么会显示此错误吗?此外,它没有填充我的自定义字段。

好的,我修好了。问题出在我的新字段数组中的选项数组。以下是正确的。

array(
                'type' => 'select',
                'label' => $this->l('Parent Feature Value'),
                'name' => 'parent_id_feature_value',
                'options' => array(
                    'query' => FeatureValue::getFeatureValuesWithLang($this->context->language->id, $parent_id),
                    'id' => 'id_feature_value',
                    'name' => 'value'
                ),
                'required' => true
            ),

这里我不得不覆盖 FeatureValue class 并添加 getFeatureValuesWithLang() 函数。

public static function getFeatureValuesWithLang($id_lang, $id_feature, $custom = false)
{
    return Db::getInstance()->executeS('
        SELECT *
        FROM `'._DB_PREFIX_.'feature_value` v
        LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl
            ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.')
        WHERE v.`id_feature` = '.(int)$id_feature.'
            '.(!$custom ? 'AND (v.`custom` IS NULL OR v.`custom` = 0)' : '').'
        ORDER BY v.`position` ASC
    ', true, false);
}

实际上是在查找查询结果中不存在的 'value' 字段。因此,我覆盖了 FeatureValue class 并添加了上述方法并调用了该方法。它解决了问题。