dra8603 2016-01-08 10:10
浏览 31
已采纳

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

I have a file called Message.php in module/Cms/language directory. This file contain constants like below

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

When module is running I would like to use such constant anywhere in the module scope. I understand I can load this by modifying config_glob_paths in application.config.php

But I am looking for a way where this file will be loaded only for the module specified. Can I have some configuration in module.config.php for this. Appreciate your guidance.

  • 写回答

1条回答 默认 最新

  • duandao1931 2016-01-08 10:30
    关注

    To define the contants when the module CMS loads use the Module::onBootstrap() method.

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

    More information about the bootstrap event is documented here.

    Optionally the Module class can implement the Zend\ModuleManager\Listener\OnBootstrapListener. Which is documented here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败