Bug Report #4448
Alias key for error array
| Status: | New | Start date: | 02/14/2012 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | - | |||
| Target version: | - | |||
| Resolution: | Points: | 1 |
Description
Considering the following code:
<?php defined('SYSPATH') or die('No direct script access.');
class Model_SomeClass extends ORM
{
public function rules()
{
$validation_a = new Validation_A(new SomeDependency());
$validation_b = new Validation_B();
return array(
'field' => array(
array('not_empty'),
array(array($validation_a, 'valid')),
array(array($validation_b, 'valid')),
),
);
}
Getting error messages:
$not_empty = $error['field']['not_empty']; $foo = $error['field']['valid']; // /--- Note how we get the $bar = $error['field']['valid']; // \--- error message for both
array($validation_a, 'valid') and array($validation_b, 'valid') are stored in the same keys in the errors array. This way, you'll always get the same error message (using a message file, for example).
Maybe we could have an alias (is it a good name?) to distinct both. Something like:
return array(
'field' => array(
array('not_empty'),
array(array($validation_a, 'valid'), array('alias' => 'foo')),
array(array($validation_b, 'valid'), array('alias' => 'bar')),
),
);
Getting error messages:
$not_empty = $error['field']['not_empty']; $foo = $error['field']['foo']; // /--- Note how we get the $bar = $error['field']['bar']; // \--- error message for both. Now they are different!
Of course it's just an example. It will not fit the current Kohana's implementation.
Thank you very much.