带有额外url参数的zend acl

Ok, I am working on a basic blog concept as some practice with Zend Framework.

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

And so, I want to have a URL to access posts similar to whatever.com/blog/post/DATE/TITLE/

I am logged in as an admin, and I can view whatever.com/blog/post/ with no problems, but if I put in any other parameters, it redirects me to the index/index...

What is going wrong?!! I have no idea where the error could be, so idk what code I should post to show you where I may have made an error....

EDIT my 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_

My Auth is ok, I can log in ok, and my identity stores the correct info....

1个回答



我在Acl类中看不到任何问题。 我认为问题应该在其他地方搜索。 首先,我想看看application.ini。 然后我们尝试做出决定。 如果可以将代码发送给我或在这里发布aplication.ini。</ p>
</ div>

展开原文

原文

I can't see any problems in Acl class. I think problem should search in the other places. First I would like to see application.ini. And then we try make a decision what to do. If it is possible send me your code or publish aplication.ini here.

dptx8888
dptx8888 也许这个链接可以帮到你。 codeutopia.net/blog/tag/zend_acl
8 年多之前 回复
doz97171
doz97171 我唯一能想到的是服务器上的mod_rewrite设置或.htaccess的错误配置
8 年多之前 回复
douyan8413
douyan8413 我编辑了我的帖子以包含我的application.ini ..但我也没有看到任何问题..我想也许路由器是动作搞笑?
8 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐