Yii - Catch all incoming requests

北城余情 提交于 2019-12-23 04:18:24

问题


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.

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

Thanks for any suggestions.


回答1:


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();

 }
}

in your controller

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


来源:https://stackoverflow.com/questions/10199406/yii-catch-all-incoming-requests

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!