【问题标题】:zend acl with extra url paramaters带有额外 url 参数的 zend acl
【发布时间】:2012-03-27 15:33:31
【问题描述】:

好的,我正在研究一个基本的博客概念,作为 Zend 框架的一些练习。

我正在使用 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');
            }
        }
    }
}

所以,我想要一个 URL 来访问类似于 whatever.com/blog/post/DATE/TITLE/ 的帖子

我以管理员身份登录,我可以毫无问题地查看whatever.com/blog/post/, 但如果我输入任何其他参数,它会将我重定向到索引/索引...

怎么了?!!我不知道错误可能在哪里,所以我应该发布什么代码来告诉你我可能在哪里出错了......

编辑我的 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_

我的Auth没问题,我可以登录了,我的身份存储了正确的信息......

【问题讨论】:

    标签: php zend-framework acl


    【解决方案1】:

    我在 Acl 类中看不到任何问题。我认为问题应该在其他地方搜索。首先我想看看application.ini。然后我们尝试决定要做什么。如果可能的话,把你的代码发给我或者在这里发布 aplication.ini。

    【讨论】:

    • 我编辑了我的帖子以包含我的 application.ini .. 但我也没有看到任何问题.. 我想也许路由器的动作很有趣?
    • 我唯一能想到的是你的服务器上 mod_rewrite 的设置或 .htaccess 的错误配置
    猜你喜欢
    • 2012-10-29
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多