1
votes

I have a rather simple CakePHP app that uses the Auth component to restrict access to the admin funcitons. That all works fine and good but I use the Pages Controller to display the home page and Admin main page.

How can I set up auth to control access to pages like '/' for home and '/admin'?

3

3 Answers

4
votes

Copy the PagesController from the /cake/libs/controller/ directory into your regular /app/controller/ directory and modify it as needed.

0
votes

I don't believe you can use the Auth component to effectively protect static pages because the pages controller uses a single action, display(), to render all static pages. Since generally you'll do something like Auth->allow('display') to allow access to your static pages like '/', there isn't an effective way to specify allow/deny of individual static pages.

0
votes

this worked for me:

in your app controller:

function beforeFilter(){
    if(@$this->params['pass'][0] == 'profile') //allow \app\views\pages\profile.ctp
        $this->Auth->allow('display');

}

you also dont have to just use the $this->params['pass'] variable. there is lots of information inside the $this variable that you can use to target the correct page. you can also use the url, which is normally in the form: /pages/page-name