在yii框架中,控制器的过滤器分为执行前和执行后,这里举例是在执行控制器前的过滤。

需要在components/文件夹下定义公共的TestAction.php文件,并且实现run()方法。这个action是各个控制器公用的。

class TestController extends Controller
{
/**
* 定义外部的action
* @return array
*/
public function actions()
{
return array(
'testa' => array(
'class' => 'TestAction'
)
);
}
public function filters()
{
return array(
         //'tes+edit,modify' 仅仅edit和modify需要执行过滤
'tes-delete' //除了delete外,其他都需要执行过滤
);
}
public function filterTes($filterChain)
{
echo "this is a filter...\r\n";
/*
* 定义过滤器链,$filterChain让后面的控制器继续执行
*/
$filterChain->run();
} public function actionTe()
{
echo $this->action->id.PHP_EOL;
Yii::app()->clientScript->registerScriptFile();
echo "this is test controller...\r\n";
}
public function actionDelete()
{
echo "this is delete action...\r\n";
}
}

最新文章

  1. 各大搜索引擎智能提示API(JSONP跨域实现自动补全搜索建议)
  2. 群晖SVN Server远程访问
  3. self&super
  4. 用javascript得到客户端IP的新方法
  5. 每天一个命令day1【diff 命令】(具体实例看下一节)
  6. linux 禁止ping
  7. Power-BI 仪表盘实现动态预警
  8. Are Landing Pages Killing Your Conversion Rate?
  9. 22 高级SQL特性
  10. oracle12c(oracle12.1.0.1.0)安装指南--实测OEL5.9(RH5)
  11. ettercap+urlsnarf+driftnet+wireshark监听妹子上网
  12. 有货前端 Web-APM 实践
  13. GDAL库中WFS服务中含有中文不能获取数据的问题
  14. Android-Could not download kotlin-reflect.jar
  15. VR外包团队—国内首家VR虚拟现实主题公园即将在北京推出
  16. 【Java基础】3、Java 位运算(移位、位与、或、异或、非)
  17. J - Intersection
  18. ECharts饼状图添加事件
  19. 转:\r,\n,\r\n的区别
  20. 手机web不同屏幕字体大小高度自适应

热门文章

  1. VS2010下调试.NET源码
  2. HTML学习总结(四)【canvas绘图、WebGL、SVG】
  3. react重学
  4. android 界面布局
  5. fedora22 mysql安装
  6. iOS错误之-Presenting view controllers on detached view controllers is discouraged
  7. 使用NCoding归档进行存储数据时候报错
  8. mysql5.5修改字符编码
  9. Linux 查公网出口IP
  10. React学习笔记-03 state