Zend Framework 2 加载 php 带有常量的文件

Zend framework 2 load php file with constants

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

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

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

中的 config_glob_paths 来加载它

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

要在模块 CMS 加载时定义常量,请使用 Module::onBootstrap() 方法。

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

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

可选地,模块 class 可以实现 Zend\ModuleManager\Listener\OnBootstrapListener。即 documented here.