Yii - Catch all incoming requests

2019-06-05 00:01发布

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.

标签: php yii
1条回答
姐就是有狂的资本
2楼-- · 2019-06-05 00:14

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
 );
 }
查看更多
登录 后发表回答