代码之家  ›  专栏  ›  技术社区  ›  Dan Berlyoung

Cakephp中的条件组件加载

  •  1
  • Dan Berlyoung  · 技术社区  · 14 年前

    我正在我的项目中使用debugkit组件,但我只想在登台服务器上打开它,并且在从生产服务器运行时不加载它。

    我知道我可以用debug-config值关闭它,但是对于两个服务器,我希望将该值保持在1。

    我尝试在bootstrap.php中有条件地定义一个contstant“debug-kit”作为组件名(即“debugkit.toolbar”)或空。然后在app_控制器文件顶部的var$组件定义中使用该常量。好吧,cake不喜欢组件数组和barf中有空值。也不喜欢空字符串。

    我觉得我错过了一些东西,但看不到森林里的树木。事先谢谢!

    3 回复  |  直到 14 年前
        1
  •  3
  •   AdamGiles    14 年前

    function __construct(){
      if(DEBUG_KIT){
        $this->components[] = 'DebugKit.Toolbar'
      }
      parent::__construct();
    }
    

        2
  •  2
  •   Daniel Wright    14 年前

    app/plugins/debugkit/controllers/components/toolbar.php ToolbarComponent::initialize

    /app/tmp/logs/error.log

        3
  •  2
  •   Dan Berlyoung    14 年前

    define( 'IS_DEV', ($_SERVER['SERVER_NAME'] == 'staging.example.com') );
    

    var $components = array( 'DebugKit.Toolbar'=>array('autoRun'=>IS_DEV) );