Bug Report #2715
Access to some fields into callback
| Status: | Closed | Start date: | 03/16/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | Core | |||
| Target version: | v3.0.4 | |||
| Resolution: | invalid | Points: |
Description
It's impossible to get access to ome fields into callback method.
Example:
$post = Validate::factory($_POST)
->callback('birthday',
array('Model_Member', 'checkBirthday'));
public static function checkBirthday(Validate $post)
{
print_r($post['birthday_m']);
}
I got "ErrorException [ Notice ]: Undefined property: Validate::$birthday_m".
Of course I can check fields using $_POST['birthday_m] but this way is not good.
PS: there was such feature in Kohana_pre3.
History
Updated by Woody Gilk about 3 years ago
- Status changed from New to Closed
- Assignee set to Woody Gilk
- Resolution set to invalid
Actually you want:
public function check_birthday(Validate $post, $input)
{
echo Kohana::debug($post[$input]);
}
Updated by Valeriy Viktorovskiy about 3 years ago
- Status changed from Closed to Feedback
Your example doesn't work for Model. Please review snippet bellow.
$_POST =array('birthday_m' => 12, 'birthday_d' => 16, 'birthday_y'=>1950);
class Controller_Register extends Controller_Website {
public function action_index($invite_code = null)
{
$post = Validate::factory($_POST)
->callback('birthday_d', 'Model_Member::checkBirthday');
if ($post->check()) {
// all ok
}
}
}
class Model_Member extends Model {
public static function checkBirthday(Validate $post, $input)
{
print_r($post['birthday_m']);
}
}
Updated by Isaiah DeRose-Wilson about 3 years ago
Valery, that's because birthday_m isn't an expected field so it will be removed. You need to add a filter/label/rule/callback for brithday_m if you want to be able to use it in your validation. This would do work (and you want the not empty rule anyway!):
$_POST =array('birthday_m' => 12, 'birthday_d' => 16, 'birthday_y'=>1950);
class Controller_Register extends Controller_Website {
public function action_index($invite_code = null)
{
$post = Validate::factory($_POST)
->rule('birthday_m', 'not_empty')
->callback('birthday_d', 'Model_Member::checkBirthday');
if ($post->check()) {
// all ok
}
}
}
class Model_Member extends Model {
public static function checkBirthday(Validate $post, $input)
{
print_r($post['birthday_m']);
}
}
Updated by Valeriy Viktorovskiy about 3 years ago
Isaiah DeRose-Wilson wrote:
...because birthday_m isn't an expected field so it will be removed.
[...]
Isaiah, thanks for explanation. I didn't expect such validate behavior.
Updated by Lorenzo Pisani about 3 years ago
oops sorry o_o can't remove my own update >_>
Updated by Isaiah DeRose-Wilson about 3 years ago
- Status changed from Feedback to Closed