Trying to modify the user access in CakePHP
Trying to modify the user access in CakePHP
I'm new in CakePHP I don't know how to manage with user access. I want the user to be able to access more than login and registration page on my app if he's not logged in. Currently, he can access only these pages if he's not logged in. I want to deny access only for a certain page.
I've used this function:
public function beforeFilter(Event $event)
{
$this->Auth->allow(['Home', 'About']);
}
With this function the user can access Home and About(Home and About are .ctp files in the Pages folder from Template). But I don't know how to allow access to the pages from NewCars folder which is of course in Template. Problem is that this folder has a lot of pages and subfolders and it will take a lot to put each one of them into an array .
P.S. The page that I want to deny access it is in anoher folder name UsedCars.
1 Answer
1
You need to use $this->Auth->allow()
method in beforeFilter of your controllers to give access to all actions.
$this->Auth->allow()
Similarly you can use the below methods to deny access for actions. You have to add these in beforeFilter method.
// Deny all actions.
$this->Auth->deny();
// Deny one action
$this->Auth->deny('add');
// Deny a group of actions.
$this->Auth->deny(['add', 'edit']);
For further reference you can follow the this link
https://book.cakephp.org/3.0/en/controllers/components/authentication.html#authorization
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Have you read this section? book.cakephp.org/3.0/en/controllers/components/… If not do it now ;)
– burzum
Jun 29 at 10:41