PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] Allowing a Specific Page in Cakephp

 January 26, 2022     authentication, cakephp     No comments   

Issue

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?


Solution

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');
    }
}


Answered By - vindia
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing