[CakePHP2] find時のSQLをログに出力


CakePHPでfind時のSQLをログに出力

find実行した後に書きを記述


$this->log( $this->{モデル名}->getDataSource()->getLog(), LOG_DEBUG);
  • LOG_DEBUG: app/tmp/logs/debug.log
  • 省略時: app/tmp/logs/error.log

画面に出すなら


pr( $this->{モデル名}->getDataSource()->getLog() );

var_dump( $this->{モデル名}->getDataSource()->getLog() );

とか。

※ 注意:デバッグレベル 2以上でないと、出力されない
core.php(baserCMSの場合は install.php)に Configure::write('debug', 2); または Configure::write('debug', 3); を記述する必要あり