2016-11-11 106 views
1

我想添加一个帮助窗体,让用户上传两种语言的图像供用户选择。从prestashop管理控制器呈现帮助窗体

但是我坚持使用窗体,无法在视图中呈现它。这里是我的控制器代码:

<?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()方法?我已经尝试了管理钩子,基本上我能想象到的任何地方。

任何帮助将不胜感激!

回答

3

那么你打电话renderForm()里面renderList(),(我想你希望窗体在默认情况下显示,当你打开控制器页面),但你不分配窗体模板。

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 *} 
形式