从Prestashop Admin Controller渲染帮助程序表单 [英] Render helper form from prestashop admin controller

查看:79
本文介绍了从Prestashop Admin Controller渲染帮助程序表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个帮助程序表单,该表单允许用户上传用户可以选择的两种语言的图像.

I am trying to add a helper form that lets the user upload images for two languages that the user can select.

但是,我仍然停留在表单上,​​无法在视图中呈现它.这是我的控制器代码:

However I am stuck with the form and cannot render it in the view. Here is my controller code:

<?php

class AdminWineoHeaderImgController extends ModuleAdminController
{
    public function __construct()
    {
        $this->bootstrap = true;
        $this->lang = (!isset($this->context->cookie) ||
         !is_object($this->context->cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($this->context->cookie->id_lang);

        parent::__construct();
    }

    public function display()
    {
        parent::display();
    }

    public function renderList()
    {
        $this->renderForm();
        $return = $this->context->smarty->fetch(_PS_MODULE_DIR_.'wineoheaderimg/views/templates/hook/adminwineoimg.tpl');

        return $return;
    }

    public function renderForm()
    {
        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->module->l('Wineo Header Img Configuration'),
                    'icon' => 'icon-envelope',
                ),
                'input' => array(
                    array(
                        'type' => 'file',
                        'label' => $this->module->l('Add images'),
                        'name' => 'enable_grades',
            'id' => 'uploadwineoheaderimg',
            'required' => false,
                        'desc' => $this->module->l('Choose images that will appear on the front page.'),
                    ),
                    array(
                    'type' => 'select',
                    'label' => $this->l('Languages:'),
                    'name' => 'category',
                    'required' => true,
                    'options' => array(
                                'query' => $options = array(
                                            array(
                                              'id_option' => 1,       // The value of the 'value' attribute of the <option> tag.
                                              'name' => 'EN',    // The value of the text content of the  <option> tag.
                                            ),
                                            array(
                                              'id_option' => 2,
                                              'name' => 'BG',
                                            ),
                                ),
                                'id' => 'id_option',
                                'name' => 'name',
                               ),
                ),
                ),
                'submit' => array('title' => $this->module->l('Save')),
            ),
        );

        $helper = new HelperForm();
        $helper->table = 'wineoheaderimg';
        $helper->default_form_language = (int) Configuration::get('PS_LANG_DEFAULT');
        $helper->allow_employee_form_lang = (int) Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG');
        $helper->submit_action = 'wineo_header_img_pc_form';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->module->name.'&tab_module='.$this->module->tab.'&module_name='.$this->module->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->tpl_vars = array(
            'fields_value' => array(
                'wineo_header_img' => Tools::getValue('enable_grades', Configuration::get('WINEO_HEADER_IMG')),
            ),
            'languages' => $this->context->controller->getLanguages(),
        );

        return $helper->generateForm(array($fields_form));
    }
}

我应该在哪里调用方法renderForm()?我已经尝试了admin钩子,并且基本上尝试了所有我能想到的地方.

Where should I call the method renderForm()? I have tried in the admin hooks and basically everywhere I could imagine.

任何帮助将不胜感激!

推荐答案

好吧,您正在renderList()内调用renderForm(),(我假设您希望在打开控制器页面时默认显示该表单),但是您没有t将表单分配给模板.

Well you are calling renderForm() inside renderList(), (I assume you want the form to display by default when you open controller page) but you don't assign the form to template.

public function renderList()
{
    $form = $this->renderForm();

    // To load form inside your template
    $this->context->smarty->assign('form_tpl', $form);
    return $this->context->smarty->fetch(_PS_MODULE_DIR_.'wineoheaderimg/views/templates/hook/adminwineoimg.tpl');

    // To return form html only
    return $form;
}

因此,如果您想在adminwineoimg.tpl

{* Some HTML *}
{$form_tpl}
{* Some HTML *}

这篇关于从Prestashop Admin Controller渲染帮助程序表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆