What are the Val开发者_C百科idate::label
and Validate::labels
functions for in Kohana 3? What are they meant to be used for?
When you use the Validation class, the label() and labels() methods are to set the labels of the fields for the error messages. Taken this code:
$user = ORM::Factory('user');
// Don't forget security, make sure you sanitize the $_POST data as needed
$user->values($_POST);
// Validate any other settings submitted
$extra_validation = Validation::factory(
array('password' => Arr::get($_POST, 'password'),
'password_confirm' => Arr::get($_POST, 'password_confirm'))
);
$extra_validation->rule('password_confirm', 'matches', array(':validation', 'password_confirm', 'password'))->label('password_confirm', 'Password confirm');
try
{
$user->save($extra_validation);
// success
}
catch (ORM_Validation_Exception $e)
{
$errors = $e->errors(TRUE);
// failure
}
Loot at ->label('password_confirm', 'Password confirm')
, it sets how the field is named in the error message that you get when you do $errors = $e->errors(TRUE);
.
I hope it's clear. If not, let me know.
i guess to print out the validation errors inside the <label>
tag
labels() sets many fields with an array and label() sets one field
精彩评论