2013-12-13 3 views
0

Я создаю простую аутентификацию Zend. Все работает нормально ... пока в моем Bootstrap.php я добавляю строку $objFront->registerPlugin(new My_Controller_Plugin_Acl(), 1);.Zend Framework - аутентификация ACL

Моя библиотека/Мой файл/Controller/Plugin/Acl.php выглядит

<?php 
// library/My/Controller/Plugin/ACL.php 
class My_Controller_Plugin_ACL extends Zend_Controller_Plugin_Abstract 
{ 
    protected $_defaultRole = 'guest'; 

    public function preDispatch(Zend_Controller_Request_Abstract $request){ 
     $auth = Zend_Auth::getInstance(); 
     $acl = new My_Acl(); 
     $mysession = new Zend_Session_Namespace('mysession'); 

     if($auth->hasIdentity()) { 
      $user = $auth->getIdentity(); 
      if(!$acl->isAllowed($user->role, $request->getControllerName() . '::' . $request->getActionName())) { 
       $mysession->destination_url = $request->getPathInfo(); 

       return Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->setGotoUrl('auth/noauth'); 
      } 
     } else { 
      if(!$acl->isAllowed($this->_defaultRole, $request->getControllerName() . '::' . $request->getActionName())) { 
       $mysession->destination_url = $request->getPathInfo(); 

       return Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->setGotoUrl('auth/login'); 
      } 
     } 
    } 
} 

моя библиотека/Мой файл/Acl.php выглядит файл

<?php 
// library/My/Acl.php 
class My_Acl extends Zend_Acl 
{ 
    public function __construct() 
    { 
        // Add a new role called "guest" 
        $this->addRole(new Zend_Acl_Role('guest')); 
        // Add a role called user, which inherits from guest 
        $this->addRole(new Zend_Acl_Role('user'), 'guest'); 
        // Add a role called admin, which inherits from user 
        $this->addRole(new Zend_Acl_Role('admin'), 'user'); 
  
        // Add some resources in the form controller::action 
        $this->add(new Zend_Acl_Resource('error::error')); 
        $this->add(new Zend_Acl_Resource('auth::login')); 
        $this->add(new Zend_Acl_Resource('auth::logout')); 
        $this->add(new Zend_Acl_Resource('index::index')); 
  
        // Allow guests to see the error, login and index pages 
        $this->allow('guest', 'error::error'); 
        $this->allow('guest', 'auth::login'); 
        $this->allow('guest', 'index::index'); 
        // Allow users to access logout and the index action from the user controller 
        $this->allow('user', 'auth::logout'); 
        $this->allow('user', 'user::index'); 
        // Allow admin to access admin controller, index action 
        $this->allow('user', 'admin::index'); 
  
        // You will add here roles, resources and authorization specific to your application, the above are some examples 
    } 
} 

Bootstrap.php

<?php 
require_once '../library/Zend/Loader.php'; 
Zend_Loader::registerAutoload(); 
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{ 
    protected function _initSession(){ 
     Zend_Session::start(); 
    } 

    protected function _initPlugins() 
    { 
     $autoloader = Zend_Loader_Autoloader::getInstance(); 
     $autoloader->registerNamespace('My_'); 

     $objFront = Zend_Controller_Front::getInstance(); 
     // $objFront->registerPlugin(new My_Controller_Plugin_Acl(), 1); 
     return $objFront; 
    } 
} 

Я не знаю, где проблема. Может кто-нибудь проверить мой код и дать мне совет?

Thank you.

+1

Какая ошибка вы получаете? –

ответ

0

Проблема заключается в комментировал линии, которую вы сделали

// $objFront->registerPlugin(new My_Controller_Plugin_Acl(), 1); 

Имя класса

class My_Controller_Plugin_ACL 

уведомление в uppercases ACL не Acl как в комментировал код твоей :) И, пожалуйста, в следующий раз задайте свой вопрос. И скажите нам, в чем проблема :)

Смежные вопросы