Skip to content

Instantly share code, notes, and snippets.

@fitzagard
Created December 1, 2011 20:38
Show Gist options
  • Save fitzagard/1419668 to your computer and use it in GitHub Desktop.
Save fitzagard/1419668 to your computer and use it in GitHub Desktop.
Li3 Filter Example
class Base extends \lithium\data\Model {
public $validates = array();
public static function __init(array $options = array()){
parent::__init($options);
/**
* Add created date to every document created
*/
static::applyFilter('create', function($self, $params, $chain){
$params['data']['created_date'] = new MongoDate();
return $chain->next($self, $params, $chain);
});
/**
* Add modified date to every document created
*/
static::applyFilter('save', function($self, $params, $chain){
$params['data']['modified_date'] = new MongoDate();
return $chain->next($self, $params, $chain);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment