Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

authentication - Allowing a Specific Page in Cakephp

I understand how to allow certain controller actions for non-logged in users. But, I can't find any documentation on how to allow access to specific pages. The controller is pages and the action is display. But, I don't want to allow the user to see all pages, just the about page.

So, what is the correct way to allow guests access to some, but not all, pages?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm afraid you can't do that using the standard functions that AuthComponent gives you. You have to create your own logic for that in the pages_controller's display action.

Something like (pseudo-code style)

# in app/controllers/pages_controller.php
var $allowedPages = array('one', 'two');

function display($page) {
    if(in_array($page, $allowedPages) || $this->User->loggedin) {
        $this->render($page);
    } else {
        $this->render('not_allowed');
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...