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?
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.
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.
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'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With