加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

在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”.
我不想将访问者重定向到另一个页面. (因为adsense问题)

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

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

class MyController extends AppController {
    function beforeFilter() {
        if ( $authorization == false )  {
                $this->render('anotherview');
                //exit();
            }
        }
    }

    function index() {
        // show authorized staff
    }           
}
尝试:
$this->response->send();
$this->_stop();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读