Search code examples
phpprestashopprestashop-1.7

Get name of module in PrestaShop front controller


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().


Solution

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