好的,我正在研究一个基本的博客概念,作为Zend Framework的一些实践。
我正在使用Zend 1.11
<?php
class App_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
// resources
$acl = new Zend_Acl();
$acl->addRole(new Zend_Acl_Role('guest'));
$acl->addRole(new Zend_Acl_Role('free'), 'guest');
$acl->addRole(new Zend_Acl_Role('paid'), 'free');
$acl->addRole(new Zend_Acl_Role('admin'), 'paid');
$acl->add(new Zend_Acl_Resource('index'));
$acl->add(new Zend_Acl_Resource('auth'));
$acl->add(new Zend_Acl_Resource('error'));
$acl->add(new Zend_Acl_Resource('user'));
$acl->add(new Zend_Acl_Resource('page'));
$acl->add(new Zend_Acl_Resource('blog'));
$acl->add(new Zend_Acl_Resource('admin'));
// set up the access rules
// everyone has full access to index, error and auth
$acl->allow(null, array('index', 'error', 'auth', 'blog', 'page'));
$acl->allow('guest', array('index', 'error', 'auth', 'blog', 'page'));
$acl->allow('admin', null);
// a guest can only read content and login
// $acl->deny('guest', 'blog', 'comment');
// free users can access the user panel
$acl->allow('free', 'user');
// cms users can also work with content
//$acl->allow('user', 'page', array('list', 'create', 'edit', 'delete'));
// administrators can do anything
$acl->allow('admin', null);
// load the auth instance
$auth = Zend_Auth::getInstance();
// set a default role of guest
if ($auth->hasIdentity()) {
$identity = $auth->getIdentity();
$role = strtolower($identity->role);
} else{
$role = 'guest';
}
// check the request
$controller = $request->controller;
$action = $request->action;
// verify they have permission
if (!$acl->isAllowed($role, $controller, $action)) {
if ($role == 'guest') {
$request->setControllerName('auth');
$request->setActionName('login');
} else {
$request->setControllerName('error');
$request->setActionName('noauth');
}
}
}
}
所以,我希望有一个网址来访问类似于whatever.com/blog/post/DATE/TITLE/
我以管理员身份登录,我可以毫无问题地查看whatever.com/blog/post/
,
但如果我输入任何其他参数,它会将我重定向到索引/索引......
出了什么问题?!!我不知道错误可能在哪里,所以idk我应该发布什么代码来告诉你我可能在哪里犯了错误....
编辑我的application.ini
; ------------------------------------------------------
[production]
; ------------------------------------------------------
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.frontController.plugins.acl = "App_Controller_Plugin_Acl"
resources.view.helperPath.App_View_Helper_ = "App/View/Helper/"
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = zendcasts
autoloaderNamespaces.app = App_
我的身份验证没问题,我可以登录确定,我的身份存储了正确的信息......
答案 0 :(得分:0)
我在Acl类中看不到任何问题。我认为问题应该在其他地方搜索。首先,我想看看application.ini。然后我们尝试做出决定。如果可以将代码发送给我或在这里发布aplication.ini。