在Kohana处理用户更新验证


Handle User update Validation in Kohana

当在try-catch块内对我的Model_Auth_user调用update_user()时,但我在$e->错误("validation")调用中得到了一个多维数组,其结构如下:

Array
(
    [_external] => Array
        (
            [password] => Array
                (
                    [0] => min_length
                    [1] => Array
                        (
                            [0] => asdf
                            [1] => 8
                        )
                )
        )
)

在这里,我通常会得到一个不带_external包装器的数组。有人知道发生了什么事吗?

我认为Kohana在您指定的"validation"文件中找不到消息,所以它以"file/field/rule"的形式返回消息。

看看这里:http://kohanaframework.org/3.2/guide/api/Validation#errors

特别是这些条件:

if ($message = Kohana::message($file, "{$field}.{$error}"))
{
    // Found a message for this field and error
}
elseif ($message = Kohana::message($file, "{$field}.default"))
{
    // Found a default message for this field
}
elseif ($message = Kohana::message($file, $error))
{
    // Found a default message for this error
}
elseif ($message = Kohana::message('validation', $error))
{
    // Found a default message for this error
}
else
{
    // No message exists, display the path expected
    $message = "{$file}.{$field}.{$error}";
}

此外,我认为您需要将消息文件存储在以下位置:/application/messages/validation/external.php