Search code examples
ormkohanakohana-orm

How to apply one filter function to all fields in ORM?


I have a Model class:

class Model_Feedback extends ORM {
    public function filters() {
        return array(
            'username' => array(
                array('trim'),
            ),
            'email' => array(
                array('trim'),
            ),
            'tel' => array(
                array('trim'),
            ),
            'text' => array(
                array('trim'),
            ),
        );
    }
}

Is there a way to trim all fields at once and not to define separate trim filter to every field?


Solution

  • Yes, Kohana allows this via a wildcard as you can see in run_filter(), instead of setting a column as key, use TRUE

    public function filters() {
        return array(
            TRUE => array(
                array('trim'),
            ),
        );
    }