Home > Article > PHP Framework > How to use yii filter
How to use yii filter
A filter is a piece of code that can be configured to be executed before or after the controller action is executed.
For example, access control filters will be executed to ensure that the user is authenticated before performing the requested action;
Performance filters can be used to measure the time it takes for the controller to execute.
An action can have multiple filters. Filters are executed in the order they appear in the filter list. Filters can prevent actions and other subsequent filters from executing.
The public function filters() method of the controller must be overridden in the controller to set which filter affects which action.
Usage example:
class CController{ public function filterAccessControl($filterChain) { //这里是你的逻辑 $filterChain->run(); } } class UserController extents CController{ public function filters() { return array{ 'AccessControl' // 这里就过滤了 } } public function actionIndex(){ } }
(Related tutorial recommendations: yii framework)
The above is the detailed content of How to use yii filter. For more information, please follow other related articles on the PHP Chinese website!