Php 如何使用HelpPerform在模板中插入图像?

Php 如何使用HelpPerform在模板中插入图像?,php,forms,prestashop-1.7,Php,Forms,Prestashop 1.7,我正在使用PrestaShop 1.7创建一个自定义模块,我希望能够上传背景图像。如果定义了background\u image字段,则应显示图像 我能做到,但是图像在表单之外,正如你在下图中看到的那样 图像应显示在背景图像字段的正上方,如下所示(见下文) 这是我的.tpl文件: {if isset($background_image)} <div> <div class="col-lg-3"></div> <div>

我正在使用PrestaShop 1.7创建一个自定义模块,我希望能够上传背景图像。如果定义了
background\u image
字段,则应显示图像

我能做到,但是图像在表单之外,正如你在下图中看到的那样

图像应显示在背景图像字段的正上方,如下所示(见下文)

这是我的.tpl文件:

{if isset($background_image)}
<div>
    <div class="col-lg-3"></div>
    <div>
        <img src="/modules/cb_sectionaboutus/img/{$background_image}" class="img-thumbnail" width="400" />
    </div>
</div>
{/if}
<>如何使用HelpExtudio/

将上载的图像插入窗体的中间?


我更喜欢使用HelpPerform的解决方案,但我不知道它是否有效,所以我会接受任何给我一个好解决方案的答案。

PHP文件-
getConfigForm
函数

protected function getConfigForm()
{
    // ADDED THESE LINES
    $image = '';
    $background_image = $this->getDataFromDB()['background_image'];
    if ($background_image) {
        $image_url = $background_image ? '/modules/cb_sectionaboutus/img/' . $background_image : '';
        $image = '<div class="col-lg-6"><img src="' . $image_url . '" class="img-thumbnail" width="400"></div>';
    }

    return array(
        'form' => array(
            'legend' => array(
                'title' => $this->l('Settings'),
                'icon' => 'icon-cogs'
            ),
            'input' => array(
                array(
                    'type' => 'file',
                    'label' => $this->l('Background Image'),
                    'name' => 'background_image',
                    'desc' => $this->l('Maximum image size: ') . $this->upload_file_size_limit_in_mb . ' MB.',
                    'display_image' => true,
                    'image' => $image  // ADDED THIS OPTION
                ),
                array(
                    'type' => 'textarea',
                    'label' => $this->l('Title'),
                    'name' => 'title',
                    'desc' => $this->l('Enter the title'),
                    'class' => 'rte',
                    'autoload_rte' => true
                )
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            ),
        ),
    );
}
受保护的函数getConfigForm()
{
//添加了这些行
$image='';
$background_image=$this->getDataFromDB()['background_image'];
如果($background\u image){
$image\u url=$background\u image?'/modules/cb\u sectionaboutus/img/。$background\u image:'';
$image='';
}
返回数组(
'form'=>数组(
“图例”=>数组(
'title'=>$this->l('Settings'),
'图标'=>'图标齿'
),
'输入'=>数组(
排列(
'类型'=>'文件',
'label'=>this->l('Background Image'),
“名称”=>“背景图片”,
'desc'=>$this->l('Maximum image size:')。$this->上载文件大小大小大小大小大小大小限制,单位为mb。'mb',
“显示图像”=>true,
'image'=>$image//添加了此选项
),
排列(
'type'=>'textarea',
'label'=>this->l('Title'),
“名称”=>“标题”,
'desc'=>this->l('输入标题'),
“类”=>“rte”,
“自动加载”=>真
)
),
“提交”=>数组(
'title'=>$this->l('Save'),
),
),
);
}

并从模板中删除所有内容。PHP文件-
getConfigForm
函数

protected function getConfigForm()
{
    // ADDED THESE LINES
    $image = '';
    $background_image = $this->getDataFromDB()['background_image'];
    if ($background_image) {
        $image_url = $background_image ? '/modules/cb_sectionaboutus/img/' . $background_image : '';
        $image = '<div class="col-lg-6"><img src="' . $image_url . '" class="img-thumbnail" width="400"></div>';
    }

    return array(
        'form' => array(
            'legend' => array(
                'title' => $this->l('Settings'),
                'icon' => 'icon-cogs'
            ),
            'input' => array(
                array(
                    'type' => 'file',
                    'label' => $this->l('Background Image'),
                    'name' => 'background_image',
                    'desc' => $this->l('Maximum image size: ') . $this->upload_file_size_limit_in_mb . ' MB.',
                    'display_image' => true,
                    'image' => $image  // ADDED THIS OPTION
                ),
                array(
                    'type' => 'textarea',
                    'label' => $this->l('Title'),
                    'name' => 'title',
                    'desc' => $this->l('Enter the title'),
                    'class' => 'rte',
                    'autoload_rte' => true
                )
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            ),
        ),
    );
}
受保护的函数getConfigForm()
{
//添加了这些行
$image='';
$background_image=$this->getDataFromDB()['background_image'];
如果($background\u image){
$image\u url=$background\u image?'/modules/cb\u sectionaboutus/img/。$background\u image:'';
$image='';
}
返回数组(
'form'=>数组(
“图例”=>数组(
'title'=>$this->l('Settings'),
'图标'=>'图标齿'
),
'输入'=>数组(
排列(
'类型'=>'文件',
'label'=>this->l('Background Image'),
“名称”=>“背景图片”,
'desc'=>$this->l('Maximum image size:')。$this->上载文件大小大小大小大小大小大小限制,单位为mb。'mb',
“显示图像”=>true,
'image'=>$image//添加了此选项
),
排列(
'type'=>'textarea',
'label'=>this->l('Title'),
“名称”=>“标题”,
'desc'=>this->l('输入标题'),
“类”=>“rte”,
“自动加载”=>真
)
),
“提交”=>数组(
'title'=>$this->l('Save'),
),
),
);
}
并从模板中删除所有内容。