2012-04-17 67 views
1

Yii中有什么方法可以捕获所有传入请求,并在触发函数时采取行动。我想要一个电子邮件扩展,可以设置为类似的情况,当文档/更新被触发或函数SaveDocument被触发发送电子邮件x。Yii - 捕获所有传入的请求

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

感谢您的任何建议。

回答

4

在控制器中创建一个类过滤器保护/过滤/ 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 
); 
}