如何在prestashop中添加管理选项卡而不扩展控制器?

如何在prestashop中添加管理选项卡而不扩展控制器?,prestashop,Prestashop,我想添加“管理”选项卡,我定义了一个控制器,并使用以下功能安装该选项卡: public function installTab($class_name, $tabname) { $tab = new Tab(); // Define the title of your tab that will be displayed in BO $tab->name[$this->context->language->id] = $tabname;

我想添加“管理”选项卡,我定义了一个控制器,并使用以下功能安装该选项卡:

public function installTab($class_name, $tabname)  {
    $tab = new Tab();
    // Define the title of your tab that will be displayed in BO
    $tab->name[$this->context->language->id] = $tabname;
    // Name of your admin controller
    $tab->class_name = $class_name;
    // Id of the controller where the tab will be attached
    // If you want to attach it to the root, it will be id 0 (I'll explain it below)
    $tab->id_parent = 0;
    $tab->active = 1;
    // Name of your module, if you're not working in a module, just ignore it, it will be set to null in DB
    $tab->module = $this->name;
    // Other field like the position will be set to the last, if you want to put it to the top you'll have to modify the position fields directly in your DB
    $tab->add();
    return true;
  }
我的控制器定义如下:

class AdminBarCodeGeneratorAdminController extends AdminController
{


 /** @var Smarty */
    public $smarty;
    public function __construct(){
        parent::__construct();
    }

public function initContent()
{
    parent::initContent();
    $scan_form=$this->renderForm();
    $this->smarty->assign('scan_form',$scan_form);
    $this->setTemplate(_PS_MODULE_DIR_.'BarCodeGenerator/views/templates/admin/tabs/scan.tpl');  
}

// public function display(){
// $smarty = $this->context->smarty;
// $scan_form=$this->renderForm();
// $smarty->assign('scan_form',$scan_form);
//  return $this->display(__FILE__, 'views/templates/admin/tabs/scan.tpl');

// }

protected function renderForm()
{
    $this->loadAsset();
    $helper = new HelperForm();
    $helper->show_toolbar = false;
    $helper->table = $this->table;
    $helper->module = $this;
    $helper->default_form_language = $this->context->language->id;
    $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);

    $helper->identifier = $this->identifier;
    $helper->submit_action = $action;
    $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
        .'&configure='.$this->name.'&module_name='.$this->name;
    
        
          $helper->currentIndex .= '&id_BarCodeGenerator='.(int)Tools::getValue('id_BarCodeGenerator');
     

    $helper->token = Tools::getAdminTokenLite('AdminModules');
   
    
    $helper->tpl_vars = array(
        'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
        'languages' => $this->context->controller->getLanguages(),
        'id_language' => $this->context->language->id,
        
    );


    return $helper->generateForm(array($this->getConfigForm()));




}

public function getConfigFormValues(){
    return array(
        'prefixe2'=>Tools::getValue('prefixe2'),
        'reference'=>Tools::getValue('reference'),
        'key'=>Tools::getValue('key')
    );
}

protected function getConfigForm(){
    return array(

        'form' => array(
            'legend' => array(
            'title' => $this->l('Scan des codes barres'),
            'icon' => 'icon-qrcode',
            ),
            'input' => array(
     
                array(
                    'col' => 3,
                    'type' => 'text',
                    //'prefix' => '<i class="icon icon-envelope"></i>',
                    'desc' => $this->l('Entrez le prefix du code barre'),
                    'name' => 'prefixe2',
                    'label' => $this->l('Prefixe'),
                    'required'=>true
                ),
                array(
                    'col' => 3,
                    'type' => 'text',
                    //'prefix' => '<i class="icon icon-envelope"></i>',
                    'desc' => $this->l('Entrez la reférence de la commande'),
                    'name' => 'reference',
                    'label' => $this->l('Reférence commande'),
                    'required'=>true
                ),
                array(
                    'col' => 3,
                    'type' => 'text',
                    //'prefix' => '<i class="icon icon-envelope"></i>',
                    'desc' => $this->l('Entrez la clé du code barre'),
                    'name' => 'key',
                    'label' => $this->l('key'),
                    'required'=>true
                ),
             
        ),
            'submit' => array(
                'title' => $this->l('Mettre à jour le statut'),
            ),
           
        ),
        
   
        );
}
在这种情况下,挂钩甚至没有成功安装

-通过在
config/routes.yml

scanTab: 
path: BarCodeGenerator/demo
methods: [GET]
defaults:
  _controller: 'BarCodeGenerator/controllers/admin/AdminBarCodeGeneratorAdminController::initContent'
  _legacy_controller: 'AdminBarCodeGeneratorAdminController'
  _legacy_link: 'AdminBarCodeGeneratorAdminController'

但是这些方法都不起作用

是否可以在“store/controllers/admin/”文件夹中手动添加此控制器?您的意思是直接在prestashop文件夹中添加控制器,我认为这是不可行的,因为它是一个模块,所以每次我想在商店中安装它时,我都会按照您说的做,什么不好@CrezzurYeah,但几乎每个人都启用了覆盖,几乎所有模块都使用它
scanTab: 
path: BarCodeGenerator/demo
methods: [GET]
defaults:
  _controller: 'BarCodeGenerator/controllers/admin/AdminBarCodeGeneratorAdminController::initContent'
  _legacy_controller: 'AdminBarCodeGeneratorAdminController'
  _legacy_link: 'AdminBarCodeGeneratorAdminController'