Zend ACL — преобразовать разрешение в общедоступный

Мне нужен ACL для моего проекта, я смотрел Александр Романенко, видео Я искал Zend ACL, который, кажется, покрывает мои потребности. Это так удивительно, и я реализовал это:

models / LibraryAcl.php:

<?php
class Model_LibraryAcl extends Zend_Acl
{
public function __construct()
{

$this ->add (new Zend_Acl_Resource('index'));
$this ->add (new Zend_Acl_Resource('authentication','login'));
$this-> add (new Zend_Acl_Resource('list'),'books');

$this->addRole(new Zend_Acl_Role('user'));
$this->addRole(new Zend_Acl_Role('admin'),'user');

$this->allow ('user','user');
$this->allow ('user','index');
$this ->allow('admin','books', 'list' ));

}
}

плагины / AccessCheck.php:

<?php
class Plugin_AccessCheck extends  Zend_Controller_Plugin_Abstract{

private $_acl = null;
private $_auth = null;

public function __construct(Zend_Acl $acl , Zend_Auth $auth){
$this->_acl = $acl;
$this->_auth = $auth;
}public function preDispatch(Zend_Controller_Request_Abstract $request){
$resource = $request->getControllerName();
$action = $request->getActionName();
$identity = $this->_auth->getStorage()->read();
$role = $identity->role;

if (!$this->_acl ->isAllowed($role,$resource,$action) ){
$request->setControllerName('authentication')
->setActionName('login');

}
}
}

Все, что я хочу, — это разрешить всем людям (администратору, пользователю и тем, кто еще не вошел в систему) доступ к странице входа (аутентификация / вход в систему -> имя контроллера: аутентификация, имя действия: вход в систему)

ОБНОВИТЬ:
Я обнаружил, что должен использовать гостя в качестве роли и установить разрешение для этой роли.

2

Решение

$this->addRole(new Zend_Acl_Role('guest'));
$this->addRole(new Zend_Acl_Role('user'), 'guest');
$this->addRole(new Zend_Acl_Role('admin'), 'user');

$this->allow('guest', 'authentication', 'login');
1

Другие решения

менять AccessCheck.php:

<?php
class Plugin_AccessCheck extends  Zend_Controller_Plugin_Abstract{

const UNAUTHORIZED_ACCESS = 'UNAUTHORIZED_ACCESS';

public function preDispatch(Zend_Controller_Request_Abstract $request){
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()){
$role = $auth->getIdentity();
}else{
$role = 'guest';
}
$acl = new Model_LibraryAcl();
$resource = $request->getControllerName();
$action = $request->getActionName();if ($acl->isAllowed($role,$resource,$action) ){

$request->setControllerName('authentication')
->setActionName('login');

}
}
}

И добавить его в LibraryAcl.php

$this->addRole(new Zend_Acl_Role('guest'));
$this->addRole(new Zend_Acl_Role('user'), 'guest');
$this->addRole(new Zend_Acl_Role('admin'), 'user');

$this->allow('guest', 'authentication', 'login');
1

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector