在 PrestaShop 前端控制器中获取模块的名称 [英] Get name of module in PrestaShop front controller

查看:41
本文介绍了在 PrestaShop 前端控制器中获取模块的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PrestaShop(特别是 v1.7.5)中,可以获得实例 模块类的调用

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.

'theModuleName' 是否可以通过其他设置或变量使用,还是需要硬编码?

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

它也应该用作 getModuleLink() 的第一个参数.

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

推荐答案

您可以通过以下方式访问模块名称(以及模块类中的其余部分):

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

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

以 Prestashop 核心模块Cronjobs"为例,您还可以像这样在前端控制器中运行模块方法:

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

这篇关于在 PrestaShop 前端控制器中获取模块的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆