Get name of module in PrestaShop front controller

后端 未结 2 427
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 06:37

In PrestaShop (specifically v1.7.5) one can get an instance of the module class by calling

$module = Module::getInstanceByName(\'theModuleName\');

相关标签:
2条回答
  • 2020-12-22 07:11

    If you are working in a child from ProductListingFrontController, this->module is not defined. If you call the module with getInstanceByName, you get an instance in order to work with it later. The string way doesn´t work in Listing controllers.

    class mymoduleMyControllerModuleFrontController extends ProductListingFrontControllerCore
         {
            public function init()
            {
                parent::init();
        
                $this -> module = Module::getInstanceByName('mymodule');
        }
    }
    
    0 讨论(0)
  • 2020-12-22 07:13

    You can access the module name (along with the rest from the module class) by:

    $theModuleName = $this->module->name;
    

    Using Prestashop core module "Cronjobs" as an example, you can also run module methods inside a front controller like this:

    class CronjobsCallbackModuleFrontController extends ModuleFrontController
    {
        public function postProcess()
        {
            $this->module->sendCallback();
            die;
        }
    }
    
    0 讨论(0)
提交回复
热议问题