代码之家  ›  专栏  ›  技术社区  ›  Shard Brian Ellis

关闭控制器操作中的调试工具包,cakephp

  •  5
  • Shard Brian Ellis  · 技术社区  · 16 年前

    我目前正在开发cakephp应用程序中的一个导出函数,我正在做一个查询,每个导出大约有10000行,cake可以处理这些导出,但是调试工具包似乎使用了大量的内存,占用了我超过128MB的内存。

    我试过在函数的顶部编写这个函数,但debugkit仍在使用大量的内存。

    Configure::write('debug',0);
    
    6 回复  |  直到 9 年前
        1
  •  9
  •   Benjamin Pearson    16 年前

    hypercas建议beforefilter()回调作为适当的解决方案是正确的。

    在操作(即,导出)所在的控制器中,代码可能看起来类似这样:

    function beforeFilter() {
        // filter actions which should not output debug messages
        if(in_array($this->action, array('export'))) {
            Configure::write('debug', 0);
        }
    }
    

    你可以调整 array('export') 包括所有要阻止调试的操作。

        2
  •  9
  •   Community Mohan Dere    8 年前

    只是为了提高 Benjamin Pearson's answer . 卸载组件而不是关闭调试。

    public function beforeFilter() {
        parent::beforeFilter();
    
        if(in_array($this->action, array('export'))) {
            $this->Components->unload('DebugKit.Toolbar');
        }
    }
    
        3
  •  0
  •   HyperCas    16 年前

    使用

    Configure::write('debug',0);
    

    在/app/config/core.php中

    或者在控制器的beforefilter()回调中使用它。如果不手动检查当前操作(在 $this->参数[‘action’] )

    如果您的模型有多个关联,您应该查看可包含的行为。

    http://book.cakephp.org/view/51/Controller-Attributes

        4
  •  0
  •   ondrobaco    16 年前

    也可以将config.php中的调试级别切换为0。这将禁用调试工具包automatically+,您的应用程序将使用更少的内存。

        5
  •  0
  •   Jahidul Islam    10 年前

    在Cakephp3打开 引导程序 文件在 配置 文件夹 注释或删除debugkit加载

    if (Configure::read('debug')) {
       // Plugin::load('DebugKit', ['bootstrap' => true]);
    }
    

    就这些……它将从应用程序中卸载debugkit

        6
  •  0
  •   Alexey Zimarev willbt    9 年前

    禁用 debug_kit 苍蝇

    class AppController extends Controller {
         public function beforeFilter() {
             Configure::write('debug', 0);
         }
    }