在CakePHP的beforeFilter中渲染后停止执行

前端之家收集整理的这篇文章主要介绍了在CakePHP的beforeFilter中渲染后停止执行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的Cake PHP 2应用程序中,我遇到了beforeFilter的问题.
this thread它运作良好.因为CakePHP的旧版本.

在我的代码中,如果用户未获得授权,我想向他显示“anotherview.ctp”.
我不想将访问者重定向到另一个页面. (因为adsense问题)

当我在beforeFilter中使用“this-> render”时,我的“index”操作中的代码也会运行.
我想在“beforeFilter”的最后一行之后停止执行.
当我将“exit()”添加到beforeFilter时,它破坏了我的代码.

如何在不破坏代码的情况下在beforeFilter中停止执行?

  1. class MyController extends AppController {
  2. function beforeFilter() {
  3. if ( $authorization == false ) {
  4. $this->render('anotherview');
  5. //exit();
  6. }
  7. }
  8. }
  9.  
  10. function index() {
  11. // show authorized staff
  12. }
  13. }
尝试:
  1. $this->response->send();
  2. $this->_stop();

猜你在找的PHP相关文章