baker
baker

Reputation: 241

How to remove auth from the pages controller in CakePHP?

I'm using CakePHP's Auth component and it's in my app_controller.php.

Now I want to allow specific views from the pages controller. How do I do that?

Upvotes: 8

Views: 9440

Answers (3)

rajesh_kw
rajesh_kw

Reputation: 1592

I haven't tried the other ways but this is also the right way to allow access to all those static pages as display is that 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'));

Upvotes: 5

Lawrence Barsanti
Lawrence Barsanti

Reputation: 33222

You could add the following to your app_controller.

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

Then you don't have to make a copy the pages controller.

Upvotes: 11

Travis Leleu
Travis Leleu

Reputation: 4230

Copy the pages_controller.php file in cake/libs/controllers to your app/controllers/ dir. Then you can modify it to do anything you want. With the auth component, the typical way to allow specific access is like this:

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

I recommend highly copying the file to your controllers dir, rather than editing it in place, because it will make upgrading cake much easier, and less likely that you accidentally overwrite some stuff.

Upvotes: 14

Related Questions