How to remove auth from page controller in CakePHP?

I am using the CakePHP Auth component and its in app_controller.php .

Now I want to allow certain views from the page controller. How to do it?

+7
authentication cakephp
source share
3 answers

Copy the pages_controller.php file to the cake / libs / controller files in the / controller / dir application. Then you can change it to do whatever you want. Using the auth component, a typical way to allow specific access is as follows:

 class PagesController extends AppController { ... function beforeFilter() { $this->Auth->allow( 'action1', 'allowedAction2' ); } ... 

I recommend that you copy the file to the directory of your controller, rather than editing it in place, because it will simplify updating the cake and most likely you will accidentally overwrite some things.

+13
source share

You can add the following to your app_controller.

 function beforeFilter() { if ($this->params['controller'] == 'pages') { $this->Auth->allow('*'); // or ('page1', 'page2', ..., 'pageN') } } 

Then you do not need to make a copy of the page controller.

+11
source share

I have not tried other methods, but this is also the right way to allow access to all these static pages, since displaying is a common action. In app_controller:

 //for all actions $this->Auth->allow(array('controller' => 'pages', 'action' => 'display')); //for particular actions $this->Auth->allow(array('controller' => 'pages', 'action' => 'display', 'home')); $this->Auth->allow(array('controller' => 'pages', 'action' => 'display', 'aboutus')); 
+5
source share

All Articles