Question

I am using Kohana 3.1

Model:

    public function filters()
    {
        $filters = parent::filters();

        $filters['birthday'] = array(
            array('date', array('Y-m-d', strtotime(':value')))
        );

        return $filters;
    }

birthday input(form value):

23/05/1989

database output:

1969-12-31

What am I doing wrong?

Was it helpful?

Solution 2

public function filters()
{
    $filters = parent::filters();

    $filters['birthday'] = array(
        array(function($value) {
            return date('Y-m-d', strtotime($value));                
        })
    ); 

    return $filters;
}

Anonymous Methods is the answer!

Thank you all for your inputs.

OTHER TIPS

You can use the inbuilt formatting method as a callback filter

public function filters()
{
  return array(
    'birthday' => array(
      array('Format::date',array(':value','Y-m-d')),
    ),
  );
}

See http://kohanaframework.org/3.1/guide/orm/filters

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top