@babel.localeselector def get_locale(): # if a user is logged in, use the locale from the user settings user = getattr(g, 'user', None) if user is not None: return user.locale # otherwise try to guess the language from the user accept # header the browser transmits. We support de/fr/en in this # example. The best match wins. return request.accept_languages.best_match(['en','zh'])
protected function preFilter($filterChain) { // logic being applied before the action is executed //print $unit; return true; // false if the action should not be executed } protected function postFilter($filterChain) { // logic being applied after the action is executed } }
在controller中使用PerformanceFilter:
1 2 3 4 5 6 7 8 9 10 11 12 13
class PostController extends CController { ...... public function filters() { return array( array( 'application.filters.PerformanceFilter - edit, create', 'unit'=>'second', ), ); } }