PHP code example of mohit-singh / zf2auth-acl

1. Go to this page and download the library: Download mohit-singh/zf2auth-acl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mohit-singh / zf2auth-acl example snippets


 'modules' => array(
	...
        'ZF2AuthAcl'
    ),

// in config/autoload/aclAuth.local.php
'globalList' => array(
		      'Application\Controller\Index-index'
	   ),

// in config/autoload/aclAuth.local.php
'beforeLoginList' => array(
		      'Application\Controller\Index-index'
	   ),

// in config/autoload/aclAuth.local.php
'ACL_Template' =>'zf2-auth-acl/index/permission.phtml'

// Check user has role or not , return true, false
$this->userAuthRole()->userHasRole();

//Get  user current role
$this->userAuthRole()->getRoleName();

//get All valid role for the current user
$this->userAuthRole()->getUserValidRole();

//Switch between roles
$this->userAuthRole()->switchRole('ADMIN');

// Check user has role or not , return true, false
$this->roleAuth()->userHasRole();

//Get  user current role
$this->roleAuth()->getRoleName();

//get All valid role for the current user
$this->roleAuth()->getUserValidRole();

//Switch between roles
$this->roleAuth()->switchRole('ADMIN');

$roleAtuth = $serviceManager->get('roleAuthService');

// Check user has role or not , return true, false
$roleAtuth->userHasRole();

//Get  user current role
$roleAtuth->getRoleName();

//get All valid role for the current user
$roleAtuth->getUserValidRole();

//Switch between roles
$roleAtuth->switchRole('ADMIN');

    /**
     * This cache is used the disk file system to store date with the following options.
     */ 
    'fileCache' => array(
        'cache_dir' => './data/cache',
        'namespace' => 'systemCache',
        'dir_level' => 2,
        'filePermission' => 0666,
        'dirPermission' => 0755
    ),


// store item in filesystem cache
        $this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->setItem('foo', 'taxi');


// get item from filesystem cache
        echo 'Cached Item is:- '.$this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->getItem('foo');


copy vendor/mohit-singh/zf2auth-acl/config/aclAuth.local.php.dist to config/autoload/aclAuth.local.php