Skip to content

Commit

Permalink
Merge branch '3.1/develop' into 3.2/develop
Browse files Browse the repository at this point in the history
refs #4533
  • Loading branch information
zeelot committed Jun 2, 2012
2 parents dce0252 + 9750511 commit 682abe0
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions guide/orm/filters.md
@@ -1,21 +1,40 @@
# Filters # Filters


Filters in ORM work much like they used to when they were part of the Validate class in 3.0.x however they have been modified to match the flexible syntax of [Validation] rules in 3.1.x. Filters run as soon as the field is set in your model and should be used to format the data before it is inserted into the Database. Filters in ORM work much like they used to when they were part of the Validate class in 3.0.x. However, they have been modified to match the flexible syntax of [Validation] rules in 3.1.x.


Define your filters the same way you define rules, as an array returned by the `ORM::filters()` method like the following: Filters run as soon as the field is set in your model and should be used to format the data before it is inserted into the Database. Filters are defined the same way you define [rules](validation), as an array returned by the `ORM::filters()` method, like the following:


public function filters() public function filters()
{ {
return array( return array(
// Field Filters
// $field_name => array(mixed $callback[, array $params = array(':value')]),
'username' => array( 'username' => array(
// PHP Function Callback, default implicit param of ':value'
array('trim'), array('trim'),
), ),
'password' => array( 'password' => array(
array(array($this, 'hash_password')), // Callback method with object context and params
array(array($this, 'hash_password'), array(':value', Model_User::salt())),
), ),
'created_on' => array( 'created_on' => array(
// Callback static method with params
array('Format::date', array(':value', 'Y-m-d H:i:s')), array('Format::date', array(':value', 'Y-m-d H:i:s')),
), ),
'other_field' => array(
// Callback static method with implicit param of ':value'
array('MyClass::static_method'),
// Callback method with object context with implicit param of ':value'
array(array($this, 'change_other_field')),
// PHP function callback with explicit params
array('str_replace', array('luango', 'thomas', ':value'),
// Function as the callback (PHP 5.3+)
array(function($value) {
// Do something to $value and return it.
return some_function($value);
}),
),

); );
} }


Expand Down

0 comments on commit 682abe0

Please sign in to comment.