1

按照这个关于如何在后台制作标签的 prestashop 说明,我做了一个需要的类和控制器。AdminTest但是如果我想在控制器中使用辅助表单来创建表单呢?

class AdminTest extends AdminTab
  {
  public function __construct()
    {

    $this->table = 'test';
    $this->className = 'Test';
    $this->lang = false;
    $this->edit = true;
    $this->delete = true;
    $this->fieldsDisplay = array(
      'id_test' => array(
        'title' => $this->l('ID'),
        'align' => 'center',
        'width' => 25),
      'test' => array(
        'title' => $this->l('Name'),
        'width' => 200)
    );

    $this->identifier = 'id_test';

    parent::__construct();

    }


  public function displayForm()
  { 
     global $currentIndex;

    $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); 
    $languages = Language::getLanguages(); 
    $obj = $this->loadObject(true); 

    $fields_form[0]['form'] = array(
      'legend' => array(       
        'title' => $this->l('Edit carrier'),       
        'image' => '../img/admin/icon_to_display.gif'   
      ),   
      'input' => array(       
        array(           
          'type' => 'text',
          'name' => 'shipping_method',
         ),
      ),
      'submit' => array(
        'title' => $this->l('Save'),       
        'class' => 'button'   
      )
    );

    $helper = new HelperForm();
    // Module, token and currentIndex
    $helper->module = $this;
    $helper->name_controller = $this->name;
    $helper->token = Tools::getAdminTokenLite('AdminModules');
    $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

    // Language
    $helper->default_form_language = $default_lang;
    $helper->allow_employee_form_lang = $default_lang;

    // Title and toolbar
    $helper->title = $this->displayName;
    $helper->show_toolbar = true;        // false -> remove toolbar
    $helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
    $helper->submit_action = 'submit'.$this->name;
    $helper->toolbar_btn = array(
            'save' =>
            array(
                    'desc' => $this->l('Save'),
                    'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
                    '&token='.Tools::getAdminTokenLite('AdminModules'),
            ),
            'back' => array(
                    'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
                    'desc' => $this->l('Back to list')
            )
    );

    return  $helper->generateForm($fields_form);

  }

 }

但它不会工作。为什么辅助表单不起作用?

ps顺便说一句,我也想使用一种$this->setTemplate('mytemplate.tpl')方法,但这也是不可能的。

4

1 回答 1

1

要创建一个新的管理选项卡,我更喜欢使用一个模块,其中只需安装一个模块安装选项卡。我认为它更漂亮,更容易导出到其他网站。我们可以这样使用:模板、助手...

举个例子 :

在您的模块中创建此目录:controllers/admin

在先前创建的目录中创建一个新类adminTest.php

class AdminTestController extends ModuleAdminController {

}

在这个类中,您可以覆盖所有 ModuleAdminController 函数并使用模板、助手(查看类AdminController

现在在您的模块中:

class testModule extends Module {

    public function __construct() {
        $this->name = 'testmodule';
        $this->tab = 'administration';
        $this->version = '1.0';
        $this->author = 'You';
        $this->need_instance = 1;
        $this->secure_key = Tools::encrypt($this->name);

        parent::__construct();

        $this->displayName = $this->l('Admin Test Tab Module');
        $this->description = $this->l('Add a new Admin Tab in BO');
    }

    public function install() {
        return parent::install() && 
               $this->_installTab();
    }

    public function uninstall() {
        return $this->_unInstallTabs() &&
               parent::uninstall();
    }

    private function _installTabs() {
       if (!$AdminTestId = Tab::getIdFromClassName('AdminTest')):
            $tab = new Tab();
            $tab->class_name = 'AdminTest';
            $tab->module = $this->name;
            $tab->id_parent = Tab::getIdFromClassName('AdminParentOrders'); // Under Orders Tab, To add a new Tab on First level like Orders/Customers... put 0
            $tab->active = 1;
            foreach (Language::getLanguages(false) as $lang):               
               $tab->name[(int) $lang['id_lang']] = 'Admin Test';
            endforeach;
            if (!$tab->save()):
                return $this->_abortInstall($this->l('Unable to create the "Admin Test" tab'));
            endif;
        else:
            $AdminTest = new Tab((int) $AdminTestId);
        endif;
   }

   // Uninstall Tabs on Module uninstall
   private function _unInstallTabs() {

        // Delete the Module Back-office tab
        if ($id_tab = Tab::getIdFromClassName('AdminTest')) {
            $tab = new Tab((int) $id_tab);
            $tab->delete();

        return true;
    }

}

所以,当你安装你的模块时,一个新的选项卡是可用的,你可以在你的 AdminTestController 中做你想做的事情,就像一个真正的 Admin Controller

于 2014-01-24T16:58:37.423 回答