Prestashop 1.6.1助手表单字段未定义索引

Prestashop 1.6.1助手表单字段未定义索引,prestashop,smarty,form-helpers,undefined-index,formhelper,Prestashop,Smarty,Form Helpers,Undefined Index,Formhelper,我为此挣扎了好几个小时: 我正在尝试为自定义模块在Prestashop中使用HelpPerform类生成的表单添加新字段 array( 'type' => 'file', 'label' => $this->l('Button image'), 'id' => 'button_image_path', 'name' => 'button_image_path', 'image' => '<img src="'._M

我为此挣扎了好几个小时: 我正在尝试为自定义模块在Prestashop中使用HelpPerform类生成的表单添加新字段

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
我尝试在
getContent()
函数中对模块的配置页面执行此操作

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
以下字段已被接受且有效:

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
它给出了以下错误:

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
Notice on line 387 in file D:\wamp\www\qmart.ro\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code
[8] Undefined index: CROSSSELLING_NBR
但是,仍然会生成输入,如下所示:

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
array(
    'type' => 'text',
    'label' => $this->l('Number of displayed products'),
    'name' => 'CROSSSELLING_NBR',
    'desc' => $this->l('Set the number of products displayed in this block.'
)
<input type="text" name="CROSSSELLING_NBR" id="CROSSSELLING_NBR" value="" class="">

我尝试的是:

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
  • 例如,将输入类型从文本更改为颜色,会产生相同的错误
  • 更改标签内容和名称内容时,仍会出现错误
我没有更改核心文件中的任何内容

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)

因此,正在为这些输入构建表单,但这种“未定义索引”的情况仍然存在。

因此,它们显然迫使您为输入选择一些默认值

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
我通过添加以下行解决了此问题:

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
$helper->fields_value['CROSSSELLING_NBR'] = '';

根据你的密码

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
array(
    'type' => 'text',
    'label' => $this->l('Number of displayed products'),
    'name' => 'CROSSSELLING_NBR',
    'desc' => $this->l('Set the number of products displayed in this block.'
)
“desc”中有错误,需要关闭最后一个括号,这应该可以

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
array(
    'type' => 'text',
    'label' => $this->l('Number of displayed products'),
    'name' => 'CROSSSELLING_NBR',
    'desc' => $this->l('Set the number of products displayed in this block.')
)
另见下文评论。