在 Cakephp 中允许特定页面 [英] 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?
推荐答案
恐怕您无法使用 AuthComponent
提供的标准函数来做到这一点.您必须在 pages_controller
的 display
操作中为此创建自己的逻辑.
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.
类似(伪代码风格)
# 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');
}
}
这篇关于在 Cakephp 中允许特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!