I got a problem with validating models in Kohana ORM, it should throw an ORM_Validation_Exception, however, it does not. I am trying to validate an emailaddress.
Model_Emailaddress
public function rules()
{
return array(
'emailaddress' => array(
array(
'Valid::email'
),
),
);
}
Controller_Test
public function action_valid()
{
$email = ORM::factory('emailaddress');
$email->emailaddress = 'test';
try
{
$email->create();
}
catch(ORM_Validation_Exception $e)
{
echo Debug::dump($e->errors());
}
}
This example should dump an array with errors to the screen but instead it just saves the emailaddress without further notices.
When I change 'Valid::email' to 'not_empty', it does throw an exception. After some debugging I discovered that Valid::email returns false, as it should.
EDIT: As some people stated, changing 'Valid::email' to 'email' does not help. Also, when I place an exit inside the email method, the script execution will be stopped.
After some heavy, heavy debugging I discovered that the Kohana validation class contains a bug in combination with php 5.3.3. It should work, but it doesn't.
In Kohana_Validation::check()
Change
$data[$field] = Arr::get($this, $field);
To
$data[$field] = Arr::get($this->_data, $field);
In Kohana_Validation::errors()
Change
':value' => Arr::get($this, $field),
To
':value' => Arr::get($this->_data, $field),
oop.. how about just usage:
'email' insert 'Valid::email'
better usage save() method:)