私はいくつかの値を検証しています:なぜsymfony2の検証propertyPath valusが角括弧で囲まれていますか?
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(),
new Email(),
),
'password' => array(
new NotBlank(),
new MinLength(array('limit' => 6)),
new MaxLength(array('limit' => 25)),
),
));
$data = array('email' => $this->getRequest()->get('email'), 'password' => $this->getRequest()->get('password'));
$errors = $this->get('validator')->validateValue($data, $collectionConstraint);
をしかし、いくつかの理由でフィールド(のPropertyPath)は角括弧で保存されている - 私は、Sfはそれを行う理由を理解したいと思います。私は手作業ですべてのブラケットを取り除かなければならないと思われるので、私はどこかの機能が不足していると思う。 $エラーの
ダンプ:
Symfony\Component\Validator\ConstraintViolationList Object
(
[violations:protected] => Array
(
[0] => Symfony\Component\Validator\ConstraintViolation Object
(
[messageTemplate:protected] => This value should not be blank
[messageParameters:protected] => Array
(
)
[root:protected] => Array
(
[email] =>
[password] =>
)
[propertyPath:protected] => [email]
[invalidValue:protected] =>
)
[1] => Symfony\Component\Validator\ConstraintViolation Object
(
[messageTemplate:protected] => This value should not be blank
[messageParameters:protected] => Array
(
)
[root:protected] => Array
(
[email] =>
[password] =>
)
[propertyPath:protected] => [password]
[invalidValue:protected] =>
)
)
)
でもToString関数は無用です。
"[email]: This value should not be blank","[password]: This value should not be blank"
どのようにすればこのアプローチを利用できますか?私はネストされた配列の検証が[]内のインデックスで起こる可能性があることを理解できましたが、配列からの単一のインデックスのときは[]を持たないべきだと思います。バリデーションを行う人は、バリデーション(オブジェクトまたは配列)を認識している必要があります。 – aambrozkiewicz
確定的なエラーマッピングを実行する場合は、そのことを知る必要があります。上記のgetSize()と['size'](仮説)の入力を表示するフォームを考えてみましょう。エラーをマッピングするには、各違反がどのフィールドに属するかを正確に知る必要があります。 –
これは本当にラヴェルバリデーターとは違っています。ラヴェルをたくさん使った後、私はsymfonyを使用しなければなりません。とても退屈です。私はsymfonyが誰のために作られたのか理解できません。 – errogaht