Advertisement
dragonbe

Full ACL example

May 2nd, 2011
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. --- application/models/Acl.php ---
  2. <?php
  3. class Application_Model_Acl extends Zend_Acl
  4. {
  5.     public function __construct()
  6.     {
  7.         $this->addRole('reader');
  8.         $this->addRole('editor', 'reader');
  9.         $this->addRole('copywriter', 'editor');
  10.        
  11.         $this->addResource('stories');
  12.         $this->addResource('edit-stories');
  13.         $this->addResource('publish-stories');
  14.        
  15.         $this->allow('reader', 'stories', 'read');
  16.         $this->allow('editor', 'edit-stories', array ('create','update'));
  17.         $this->allow('copywriter', 'publish-stories', array ('publish'));
  18.     }
  19. }
  20.  
  21. --- application/controllers/TestController.php ---
  22. public function aclAction()
  23. {
  24.     $acl = new Application_Model_Acl();
  25.     $this->view->acl = $acl;
  26. }
  27.  
  28. --- application/views/scripts/test/acl.phtml ---
  29. <?php echo $this->htmlList(array (
  30.     'reader is allowed to read stories: ' . ($this->acl->isAllowed('reader', 'stories', 'read') ? 'true' : 'false'),
  31.     'reader is allowed to edit stories: ' . ($this->acl->isAllowed('reader', 'stories', 'edit') ? 'true' : 'false'),
  32.     'reader is allowed to create stories: ' . ($this->acl->isAllowed('reader', 'stories', 'create') ? 'true' : 'false'),
  33.     'reader is allowed to publish stories: ' . ($this->acl->isAllowed('reader', 'stories', 'publish') ? 'true' : 'false'),
  34.  
  35.     'editor is allowed to read stories: ' . ($this->acl->isAllowed('editor', 'stories', 'read') ? 'true' : 'false'),
  36.     'editor is allowed to edit stories: ' . ($this->acl->isAllowed('editor', 'stories', 'edit') ? 'true' : 'false'),
  37.     'editor is allowed to create stories: ' . ($this->acl->isAllowed('editor', 'stories', 'create') ? 'true' : 'false'),
  38.     'editor is allowed to publish stories: ' . ($this->acl->isAllowed('editor', 'stories', 'publish') ? 'true' : 'false'),
  39.  
  40.     'copywriter is allowed to read stories: ' . ($this->acl->isAllowed('copywriter', 'stories', 'read') ? 'true' : 'false'),
  41.     'copywriter is allowed to edit stories: ' . ($this->acl->isAllowed('copywriter', 'stories', 'edit') ? 'true' : 'false'),
  42.     'copywriter is allowed to create stories: ' . ($this->acl->isAllowed('copywriter', 'stories', 'create') ? 'true' : 'false'),
  43.     'copywriter is allowed to publish stories: ' . ($this->acl->isAllowed('copywriter', 'stories', 'publish') ? 'true' : 'false'),
  44.  
  45. ))?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement