Zend框架2用常量加载php文件

时间:2016-01-08 10:10:41

标签: php zend-framework zend-framework2

我在Message.php目录中有一个名为module/Cms/language的文件。该文件包含如下所示的常量

<?php
define("APPLICATION_TITLE","Test Application");
?>

当模块运行时,我想在模块范围内的任何地方使用这样的常量。我知道我可以通过修改config_glob_paths

中的application.config.php来加载它

但我正在寻找一种方法,只为指定的模块加载此文件。我可以在module.config.php中进行一些配置吗?感谢您的指导。

1 个答案:

答案 0 :(得分:1)

在模块CMS加载时使用Module::onBootstrap()方法定义容器。

class Module
{
    public function onBootstrap(Event $e)
    {
       include_once( __DIR__  . '/language/English.php');
    }
}

有关引导事件的更多信息是documented here

模块类可以选择实现Zend\ModuleManager\Listener\OnBootstrapListener。这是documented here