Cakephp不是';t显示调试消息


Cakephp isn't show debug messages

我在保存数据时遇到了一些问题。为了知道哪里出了问题,我想在控制器中使用debug($var)debug($this->myModel->validationErrors);,但它似乎没有给出任何响应。

我的情况是将一些数据发布到同一页面并保存数据

     //my controller
    if ($this->request->is('post')){
        debug($this->request->data);
      //here everything breaks with the message "Error: An Internal Error Has Occurred."
      if($this->Invoice->save($this->request->data)){
            $this->Session->setFlash('Good job, invoice is saved');
        }
     debug($this->Invoice->validationErrors);
    }

在视图端,我没有任何echo来显示调试,因为我还没有找到这样做的源。

在代码的某个地方,必须将调试模式设置为0,例如:-

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

它可能在app_controller或任何地方,因此它将无法在您的控制器中工作。

尝试在控制器中设置Configure::write('debug', 1);以使用此功能。

  debug($this->Invoice->validationErrors);

使用cakehp-debugkit插件

https://github.com/cakephp/debug_kit

也可以使用进行配置

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

尝试使用打印输出

debug($data);
pr($data);

在Core.php文件中将调试级别设置为2

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

或者,修改数据库连接以确保启用编码,因为默认情况下已注释掉

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => 'password',
    'database' => 'test',
    'prefix' => '',
    'encoding' => 'utf8',
);

尝试:

debug($this->request->data); die();