Prestashop,不能要求 Module 类

2024-02-23

Problem

Related issue https://stackoverflow.com/questions/28585399/prestashop-1-6-get-instance-of-module-class,我一直在尝试将相关解决方案应用于我的项目,但是我无法执行

Module::getInstanceByName('modulename');

我什至无法访问Module类,这使得我很难访问应用程序上下文和我自己的模块上下文

class_exists('Module')

Returns false.

我还提供了我尝试访问的模块的目录结构Module.

├── mymodule.php
├── config.xml
└── somedirectory
    └── index.php

Where mymodule.php遵循模块类指导方针 http://doc.prestashop.com/display/PS16/Creating+a+first+module#Creatingafirstmodule-Themainclass and index.php只是我尝试访问其他模块的 php 文件。对我来说最重要的是访问我自己的模块的上下文,以便我可以检索例如它的版本和其他设置。

示例来源

的例子index.php从我的testmodule,这个例子是为了1.4但我也愿意让它为之工作1.5 and 1.6

require('../../../config/settings.inc.php');
require('../../../classes/Module.php');
$instance = Module::getInstanceByName('mymodule');

这会崩溃,当我使用时

require('../../../config/settings.inc.php');
require('../../../classes/Module.php');
if (class_exists('Module')) {
    echo "class exists";
} else {
    echo "class does not exists";
}

它输出class does not exists.

我要求的理由../../../config/settings.inc.php是为了证明我可以要求一些课程并且它有效。我能够访问内部定义的常量settings.inc.php

所以文件位于相对路径../../../classes/Module.php存在并且它包含

...
public static function getInstanceByName($moduleName)
...

问题

  1. 如何正确访问Module按照建议访问特定模块实例的类here https://stackoverflow.com/questions/28585399/prestashop-1-6-get-instance-of-module-class。从自定义模块的任意文件中加载 Prestashop 类的正确方法是什么?
  2. 为什么我可以导入../../../config/settings.inc.php using require它不适用于../../../classes/Module.php?
  3. 此问题涉及 Prestashop1.4,但是我想知道这是否也适用于1.5 and 1.6,我注意到对于那些版本classes/module.php不存在而是存在classes/module/Module.php。通用解决方案将是最好的。

如果您致电您的index.php直接归档(http://www.example.com/modules/mymodule/somedirectory/index.php)您没有使用 Prestashop 内部调度程序。这意味着当您的index.php脚本被执行。

如果你想加载 Prestashop,你首先需要包含/config/config.inc.php:

require('../../../config/config.inc.php');
if (class_exists('Module')) {
    echo "class exists";
} else {
    echo "class does not exists";
}

如果您想使用 Prestashop 标准 Dispatcher 流程​​,您将必须创建一个模块前端控制器 http://doc.prestashop.com/display/PS16/Controllers+within+PrestaShop.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Prestashop,不能要求 Module 类 的相关文章