后台标签和帮助表单?

时间:2014-01-23 20:45:19

标签: prestashop prestashop-1.5

关于如何在后台制作标签的this 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);

  }

 }

但它不起作用。帮助形式为何不起作用?

P.S。顺便说一句,我也想使用$this->setTemplate('mytemplate.tpl')方法,但它也不可能。

1 个答案:

答案 0 :(得分: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中执行您想要的操作,就像真正的管理控制器一样