我一直在搜索Google,但我没有找到任何关于如何使用Kohana 3.2验证多个模型的示例。
try
{
$one = ORM::factory('one');
$one->values($this->request->post());
$one->check();
$two = ORM::factory('two');
$two->values($this->request->post());
$two->check();
}
catch(ORM_Validation_Exception $e)
{
$errors = $e->errors('models');
}
如果“one”有任何错误,则永远不会检查“two”。
答案 0 :(得分:0)
这是使用try catch
的常规行为。像下面那样重写代码应该这样做
$errors = array();
try
{
$one = ORM::factory('one')->values($this->request->post());
$one->check();
}
catch (ORM_Validation_Exception $e)
{
$errors = array_merge($errors, $e->errors('models'));
}
try
{
$two = ORM::factory('two')->values($this->request->post());
$two->check();
}
catch (ORM_Validation_Exception $e)
{
$errors = array_merge($errors, $e->errors('models'));
}