在CakePHP的beforeFilter中渲染后停止执行
发布时间:2020-12-13 22:37:05 所属栏目:PHP教程 来源:网络整理
导读:在我的Cake PHP 2应用程序中,我遇到了beforeFilter的问题. 在 this thread它运作良好.因为CakePHP的旧版本. 在我的代码中,如果用户未获得授权,我想向他显示“anotherview.ctp”. 我不想将访问者重定向到另一个页面. (因为adsense问题) 当我在beforeFilter中
在我的Cake
PHP 2应用程序中,我遇到了beforeFilter的问题.
在 this thread它运作良好.因为CakePHP的旧版本. 在我的代码中,如果用户未获得授权,我想向他显示“anotherview.ctp”. 当我在beforeFilter中使用“this-> render”时,我的“index”操作中的代码也会运行. 如何在不破坏代码的情况下在beforeFilter中停止执行? class MyController extends AppController { function beforeFilter() { if ( $authorization == false ) { $this->render('anotherview'); //exit(); } } } function index() { // show authorized staff } }
尝试:
$this->response->send(); $this->_stop(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |