0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cakephp:独自Validationのデバッグ

Posted at

まだ勉強中なのでやり方が乱暴なんですが、もっと良い方法をご存知でしたら教えて下さい。

1. バリデーションのデバッグ方法

1.1. バリデーションエラーを表示する

1.1.1 モデルでエラーメッセージを定義する

Model/名前.php
public $validate = array(
                'original' => array(
                        'timestamp' => array(
                                'rule'    => '/正規表現/',
                                'message' => 'バリデーションエラーだよ'
                        )
                  )

1.1.2 ビューでエラーメッセージを出力する

View/名前/add.ctp
echo $this->Form->error('名前.original');

1.2 実際に渡ってきているデータをdebug.logに書き出す

1.2.1 CakeValidationRule.phpをいじる

logメソッドを利用するためCakeValidationRuleクラスをObjectの小クラスにする

lib/Cake/Model/Validator/CakeValidationRule.php
class CakeValidationRule extends Object{

次に、279行に次を挿入する

lib/Cake/Model/Validator/CakeValidationRule.php
$this->log("Data under validation: ".$data[$field],LOG_DEBUG);

これで、バリデーション実行時にdebug.logにバリデーション対象のデータが書き込まれる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?