I’m using AuthComponent in CakePHP 2.
I want to show to anonymous users just the ‘home’ view and deny ‘test’ view.
Both views are inside the folder Views/Pages
If I use this code:
public function beforeFilter(){
parent::beforeFilter(); //calling parents before filter
$this->Auth->allow('home'); //allowing home only for pages controller
}
in my PagesController I’cant access any page of my PagesController, including home.ctp.
If I use:
$this->Auth->allow('display')
in my PagesController I can access any page of my PagesController, including test.ctp.
How can I solve this issue?
I tried to create a new method on my PagesController name home(). But without success.
Here is a good answer for you.
Allowing a Specific Page in Cakephp
Keep in mind that the Auth->allow is for methods. Display is the method in the pages controller. The Home page is considered a variable used in display. So you will have to do this programmatically in the Pages controller.