Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Zend_acl, router
cykcykacz
post
Post #1





Grupa: Zarejestrowani
Postów: 550
Pomógł: 9
Dołączył: 29.05.2009
Skąd: Ostrów Wielkopolski

Ostrzeżenie: (0%)
-----


Witam,
robię stronkę przy pomocy Zend Framework.
Dodałem Zend_ACL i wszystko jest wporządku do momętu kiedy chcę dodać do ACL trasy routera. Tak wygląda mój plugin ACL:
  1. <?php
  2.  
  3. class Plugin_Acl extends Zend_Controller_Plugin_Abstract
  4. {
  5. public function preDispatch(Zend_Controller_Request_Abstract $request)
  6. {
  7. // set up acl
  8. $acl = new Zend_Acl();
  9.  
  10. // add the roles
  11. $acl->addRole(new Zend_Acl_Role('guest'));
  12. $acl->addRole(new Zend_Acl_Role('user'), 'guest');
  13. $acl->addRole(new Zend_Acl_Role('administrator'), 'user');
  14. // add the resources
  15. $acl->add(new Zend_Acl_Resource('index'));
  16. $acl->add(new Zend_Acl_Resource('error'));
  17. $acl->add(new Zend_Acl_Resource('article'));
  18. $acl->add(new Zend_Acl_Resource('portfolio'));
  19. $acl->add(new Zend_Acl_Resource('contact'));
  20. $acl->add(new Zend_Acl_Resource('user'));
  21. $acl->add(new Zend_Acl_Resource('produkt-edytuj'));
  22.  
  23. // set up the access rules
  24. $acl->allow(null, array('index', 'error'));
  25. // a guest can only read content and login
  26. $acl->allow('guest', 'article');
  27. $acl->allow('guest', 'portfolio');
  28. $acl->allow('guest', 'contact');
  29. $acl->allow('guest', 'user');
  30. // cms users can also work with content
  31. $acl->deny('guest', 'article', array('add', 'edit'));
  32. // administrators can do anything
  33. $acl->allow('administrator', null);
  34.  
  35. // fetch the current user
  36. $auth = Zend_Auth::getInstance();
  37. if($auth->hasIdentity()) {
  38. $identity = $auth->getIdentity();
  39. $role = strtolower($identity->role);
  40. }else{
  41. $role = 'guest';
  42. }
  43. $controller = $request->controller;
  44. $action = $request->action;
  45. if (!$acl->isAllowed($role, $controller, $action)) {
  46. if ($role == 'guest') {
  47. $request->setControllerName('user');
  48. $request->setActionName('login');
  49. } else {
  50. $request->setControllerName('error');
  51. $request->setActionName('noauth');
  52. }
  53. }
  54. }
  55. }


I w momęcie kiedy chcę wejść na adres jako administrator http://projekt.localhost/produkt-edytuj dostaję komunikat:
Kod
Error: Not Authorized!
Sorry, you are not authorized to access this resource.


Router do aplikacji jest dodany w ten sposób!
w folderze public/index.php
  1. ...
  2. $front = Zend_Controller_Front::getInstance();
  3.  
  4. $front->setParam('useDefaultControllerAlways', false);
  5.  
  6. include_once ('router.php');
  7. ...

A sam roiter wygląda tak:
Kod
        $router = $front->getRouter();

    $route = new Zend_Controller_Router_Route_Regex(
        'produkt-edytuj/([0-9]+)',
        array(
            'module'      => 'default',
            'controller' => 'article',
            'action'      => 'edit'
        ),
        array(
            1 => 'id'
        ),
        'produkt-edytuj/%s'
    );


Dlaczego ACL nie chce wpuścić mnie do zasobu $acl->add(new Zend_Acl_Resource('produkt-edytuj')); ?

Ten post edytował cykcykacz 14.01.2012, 20:29:00
Go to the top of the page
+Quote Post

Posty w temacie
- cykcykacz   [PHP]Zend_acl, router   14.01.2012, 20:28:27
- - IceManSpy   A to nie będzie problem w linijce 31: [PHP] pobier...   14.01.2012, 20:48:00
- - cykcykacz   Dzięki. Nie pomyślałem...   14.01.2012, 20:51:12


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 4.10.2025 - 06:18