acl - Block access to pages in cakePHP -
how block access page in cakephp. page, i'm referring actual views lying in page folder.
when remove line in, works, stops users logging in. create direct loop:
$this->auth->allow('display');
basically, when user wants view page, , not logged in, redirected login (app/users/login
) page. after they've logged in, directed page last tried access.
how go this?
the problem in situation all pages shown pagescontroller same action (display()
), using different parameter (the page display). can therefore not block access display action, because block access all pages.
if number of pages limited, easiest way implement controllerauthorize
. read documentation here; using controllerauthorize
class appcontroller extends controller { public $components = array( 'auth' => array('authorize' => 'controller'), ); public function isauthorized($user = null) { // make actions public return true; } }
then, inside pages controller;
class pagescontroller extends appcontroller { public function isauthorized($user = null) { if ('display' !== $this->request->action) { // other actions; let appcontroller handle access return parent::isauthorized($user); } if (!empty($user)) { // logged-in users have access page return true; } $page = empty($this->request->params['pass'][0]) ? null : $this->request->params['pass'][0]; switch($page) { case 'home': case 'about': // etc return true; } // other pages 'private' return false; } }
just example, of course, modify fit needs
Comments
Post a Comment