Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop execution after render in beforeFilter of CakePHP

In my CakePHP 2 application i have a problem with beforeFilter. In this thread it worked well. Because of old version of CakePHP.

In my code, If user is not authorized, I want to show him "anotherview.ctp". I don't want to redirect visitor to another page. (because of adsense issues)

When i use "this->render" in beforeFilter, the code in my "index" action is also run. I want to stop the execution after the last line of "beforeFilter". When I add "exit()" to beforeFilter, it broke my code.

How can I stop execution in beforeFilter without breaking code?

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

    function index() {
        // show authorized staff
    }           
}
like image 881
trante Avatar asked May 27 '12 09:05

trante


1 Answers

Try:

$this->response->send();
$this->_stop();
like image 194
tigrang Avatar answered Oct 11 '22 21:10

tigrang