doure8758 2012-03-27 15:33
浏览 34

带有额外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条回答

  • doupa9062 2012-03-27 19:35
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。