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