我如何看到cakephp数据库保存错误?

bha*_*ral 5 database cakephp model

如果我有一个蛋糕php saveAll方法像这样:

if ($this->Video->saveAll($this->data)){
    ... // stuff that never happens, sadly
} else {
    ...
    $this->Session->setFlash('boo! hss! error here');
}
Run Code Online (Sandbox Code Playgroud)

我该如何打印出数据库错误?我试过了:

    $this->Session->setFlash('boo! hss! error here' . print_r($this->Video->validationErrors,true);
Run Code Online (Sandbox Code Playgroud)

但那不起作用(它只是向我展示了一个空数组)

cheerio!

更新:啊.所以,问题是,虽然通常我会得到数据库错误,但我使用的是旧的prg机制,而且蛋糕没有(神奇地)显示重定向页面上的db错误.

很公平,但在将来,我是多么意思在重定向页面上看到db错误(也就是问题仍然存在,只是大多数人可能只是看到了错误,而且不需要做什么得到它)

小智 6

  1. 确保config/core.php中的debug设置为2

  2. 将错误消息打印到日志文件中,如下所示:

    $ this-> log(print_r($ this-> Video-> validationErrors,true));