Skip to content

Commit

Permalink
[ja] follows cakephp#5310
Browse files Browse the repository at this point in the history
  • Loading branch information
okinaka committed Oct 22, 2017
1 parent 5f7b22a commit c84cb83
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ja/orm/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,26 @@ CakePHP は、エンティティーが保存される前に適用される「ル
return $entity->isOkLooking();
}, 'ruleName');

条件付きルールの使用
--------------------

エンティティーデータに基づいて条件付きでルールを適用することができます。 ::

$rules->add(function ($entity, $options) use($rules) {
if ($entity->role == 'admin') {
$rule = $rules->existsIn('user_id', 'Admins');

return $rule($entity, $options);
}
if ($entity->role == 'user') {
$rule = $rules->existsIn('user_id', 'Users');

return $rule($entity, $options);
}

return false;
}, 'userExists');

再利用可能なカスタムルールの作成
--------------------------------

Expand Down

0 comments on commit c84cb83

Please sign in to comment.