Get name of module in PrestaShop front controller

有些话、适合烂在心里 提交于 2019-11-28 12:45:26

问题


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

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

in the controller of a custom module.

Is 'theModuleName' available via some other setting or variable or does it need to be hardcoded?

It should also be used as first parameter to getModuleLink().


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/54469035/get-name-of-module-in-prestashop-front-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!