Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
CakePHP plugin. Allows to display only the links that can be accessed with Acl
PHP
branch: master

Merge pull request #2 from robmaurer/patch-1

Line 96 seems to not work for tables with two names because it doesn't re
latest commit a91379ce5d
@geromey authored
Failed to load latest commit information.
views/helpers
README.md
acl_utilities_app_controller.php
acl_utilities_app_model.php add block support and comments

README.md

AclUtilities Plugin for CakePHP

AclUtilities permits to translarently display or hide links in view according to Acl rules.

Installation

  • in the views, replace $this->Html->link() by $this->Acl->link()

example:

<?php echo $this->Html->link(__('List Posts', true), array('action' => 'index')); ?>

<?php echo $this->Html->link(__('Edit User', true), array('controller'=>'User','action' => 'edit')); ?>

replaced by:

<?php echo $this->Acl->link(__('List Posts', true), array('action' => 'index')); ?>

<?php echo $this->Acl->link(__('Edit User', true), array('controller'=>'User','action' => 'edit')); ?>

Be sure to use an array format for the URL.

  • in the AppController, add the helper AclUtilities.Acl

    var $helpers = array(/*...,*/ 'AclUtilities.Acl');
    
  • If you are using Auth->allowedActions or Auth->allow()
    Then you have to move them all into AppController::beforeFilter() like the following:

    function beforeFilter() { //[...] // $allowedActions = array([Controller]=>array([action1],[action2]); Configure::write('AclUtilities.allowedActions', $allowedActions = array( 'News' => array('*'), // access to all the actions 'Groups' => array(), // no access to groups 'Pages' => array('display'), 'Posts' => array('index', 'view'), 'Users' => array('login','register'), ));

      // now, we need to allow the action for the current module
      if (isset($allowedActions[$this->name]))
          $this->Auth->allow($allowedActions[$this->name]);
    

    }

And this is it; your links are now only displayed when they can be accessed!

More Examples

  • use of the option wrapper:

    • <?php echo $this->Html->link(__('List Posts', true), array('action' => 'index')); ?>
        • <?php echo $this->Acl->link(__('List Posts', true) ,array('action' => 'index') ,array('wrapper'=>'li'); ?>

          • another use of the wrapper

            Html->link(__('List Posts', true), array('action' => 'index')); ?>

            <?php echo $this->Acl->link(__('List Posts', true) ,array('action' => 'index') ,array('wrapper'=>'

            %s
            '); ?>

          • use of $this->Acl->check()

            Acl->check(array('action' => 'index'))): ?>
            Html->link(__('List Posts', true), array('action' => 'index')); ?>
              <?php endif; ?>
            

          • use of blocks (only display a block if a link is successful):

            Acl->startBlock() ?>
            Acl->link(__('List Posts', true), array('action' => 'index')); ?>
            Acl->endBlock() ?>

          Use a different Model

          In AppController::beforeFilter() add this:

          Configure::write('AclUtilities.modelName','Group');
          Configure::write('AclUtilities.modelKey','Auth.User.group_id');
          
Something went wrong with that request. Please try again.