public function filterAccessControl($filterChain)
{
// 调用 $filterChain->run() 以继续后续过滤器与动作的执行。
}
class PerformanceFilter extends CFilter
{
protected function preFilter($filterChain)
{
// 动作被执行之前应用的逻辑
return true; // 如果动作不应被执行,此处返回 false
}
protected function postFilter($filterChain)
{
// 动作执行之后应用的逻辑
}
}
class PostController extends CController
{
......
public function filters()
{
return array(
'postOnly + edit, create',
array(
'application.filters.PerformanceFilter - edit, create',
'unit'=>'second',
),
);
}
}
public function filterAccessControl($filterChain)
{
echo "--->filterAccessControl";
$filterChain->run();
}
<?php
/**
* CFilter is the base class for all filters.
*
* A filter can be applied before and after an action is executed.
* It can modify the context that the action is to run or decorate the result that the
* action generates.
*
* Override {@link preFilter()} to specify the filtering logic that should be applied
* before the action, and {@link postFilter()} for filtering logic after the action.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: CFilter.php 2799 2011-01-01 19:31:13Z qiang.xue $
* @package system.web.filters
* @since 1.0
*/
class CFilter extends CComponent implements IFilter
{
/**
* Performs the filtering.
* The default implementation is to invoke {@link preFilter}
* and {@link postFilter} which are meant to be overridden
* child classes. If a child class needs to override this method,
* make sure it calls <code>$filterChain->run()</code>
* if the action should be executed.
* @param CFilterChain $filterChain the filter chain that the filter is on.
*/
public function filter($filterChain)
{
if($this->preFilter($filterChain))
{
$filterChain->run();
$this->postFilter($filterChain);
}
}
/**
* Initializes the filter.
* This method is invoked after the filter properties are initialized
* and before {@link preFilter} is called.
* You may override this method to include some initialization logic.
* @since 1.1.4
*/
public function init()
{
}
/**
* Performs the pre-action filtering.
* @param CFilterChain $filterChain the filter chain that the filter is on.
* @return boolean whether the filtering process should continue and the action
* should be executed.
*/
protected function preFilter($filterChain)
{
return true;
}
/**
* Performs the post-action filtering.
* @param CFilterChain $filterChain the filter chain that the filter is on.
*/
protected function postFilter($filterChain)
{
}
}
<?php
class SiteController extends Controller
{
public function init()
{
//$this->layout='mylayout';
}
public function filters()
{
return array(
'AccessControl - create',
array(
'application.filters.MyFilter + create',
),
);
}
public function filterAccessControl($filterChain)
{
echo "--->filterAccessControl";
$filterChain->run();
}
public function actionCreate() {
echo "--->create action";
}
public function actionPrint() {
echo "--->print action";
}
<?php
class MyFilter extends CFilter
{
protected function preFilter ($filterChain)
{
// logic being applied before the action is executed
echo "-->MyFilter-->pre";
return true; // false if the action should not be executed
}
protected function postFilter ($filterChain)
{
echo "-->MyFilter-->post";
}
}
public function filters()
{
return array(
'AccessControl - create',
array(
'application.filters.MyFilter + create,print',
),
);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有