donglan6967 2015-05-27 00:58
浏览 52
已采纳

Prestashop 1.6模块错误:文件prestashop16 \ tools \ smarty \ sysplugins \ smarty_internal_templatebase.php中第719行的注意事项

I'm developing a module and extended AdminFeaturesController.php to display my custom field Add/Edit Feature Value, but it is showing following error in popup:

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

I think it is due to I override the function initFormFeatureValue() in my AdminFeaturesController.php file and added a new field. Here is the code for that:

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);
    }

Any idea why it is showing this error? Also, it is not populating my custom field.

  • 写回答

1条回答 默认 最新

  • duanmin0941 2015-05-27 01:53
    关注

    OK, I fixed it. The problem was with options array in my new field array. Following is the correct one.

    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
                ),
    

    Here I had to override the FeatureValue class and add the getFeatureValuesWithLang() function.

    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);
    }
    

    What is actually does is that it was finding the 'value' field which was not present in the query result. So, I override FeatureValue class and add the above method and called that one. It solved the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习或深度学习问题?困扰了我一个世纪,晚来天欲雪,能饮一杯无?
  • ¥15 c语言数据结构高铁订票系统
  • ¥15 关于wkernell.PDB加载的问题,如何解决?(语言-c#|开发工具-vscode)
  • ¥15 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?