Yii - 捕获所有传入的请求 [英] Yii - Catch all incoming requests

查看:26
本文介绍了Yii - 捕获所有传入的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Yii 中是否有一种方法可以在函数被触发时捕获并处理所有传入的请求.我想修改一个电子邮件扩展名,该扩展名可以设置为在触发文档/更新或触发函数 SaveDocument 时发送电子邮件 x.

Is there a way in Yii to catch and act upon all incoming requests are when functions are fired. I want to right an e-mail extension that can be set to something like, when documents/update is fired or function SaveDocument is fired send e-mail x.

我猜我可以通过扩展 Controller 类来做到这一点,但这已经由权限扩展完成了.

I guessing that i can do this by extending the Controller class but that is already being done by the rights extension.

感谢您的任何建议.

推荐答案

创建类过滤器 protected/filter/EmailFilter

create a class filter protected/filter/EmailFilter

EmailFilter extends CFilter{
//fired before action
protected function preFilter($filterChain)
{
 return true; // false if the action should not be executed
}
 //fired after action
 protected function postFilter()
 {
     sendEmail();

 }
}

在你的控制器中

public function filters()
 {
  return array(
  'application.filters.EmailFilter + update,saveDocument'// apply filter on update and       saveDocument action only
 );
 }

这篇关于Yii - 捕获所有传入的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆