PHP code example of pranaya / cakephp-zone-acl

1. Go to this page and download the library: Download pranaya/cakephp-zone-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/ */

    

pranaya / cakephp-zone-acl example snippets


CakePlugin::load('ZoneAcl', array('bootstrap' => true));

Configure::write('Acl.classname', 'DbAcl');
Configure::write('Acl.database', 'default');

Configure::write('Acl.classname', 'ZoneAcl.ZoneAcl');
//Configure::write('Acl.database', 'default');


class AppController extends Controller {
	public $helpers = array('ZoneAcl.ZoneAclHtml');
}

 

App::uses('ZoneAroInterface', 'ZoneAcl.Controller/Component/Acl');

class MySimpleAro implements ZoneAroInterface { 

	public function getAllowedZones($aro) { 
		// $aro contains user's session data 
		$userId = $aro['User']['id']; 
		$groupId = $aro['User']['group_id']; 
		 
		// find what zones user can access with those info 
		// you can even store the what zones the 
		// user can access in the session itself 
		$zones = array(); 
		 
		$zones[] = 'admin'; 
		$zones[] = 'general-user'; 
		
		// return array of zone names 
		//the user can access
		return $zones; 
	} 
}
 

 

App::uses('MySimpleAro', 'Path/To/Class'); 

class AppController extends Controller { 
	 
	public function beforeFilter() { 
		// plug ARO object
		ZoneAcl::setAro(new MySimpleAro()); 
	} 
}



// returns true if the current user is 
// allowed on that url
$this->ZoneAclHtml->isAllowed($url); 

// same as HtmlHelper::link() except it returns empty link
// when user is not allowed
$this->ZoneAclHtml->link($title, $url); 
ini
[settings]
case-sensitive = true

[zone:admin]
; allow all admin_ actions
url[] = '(\w)+/admin_*'

; allow all plugin's admin_ action
url[] = '(\w+)/(\w+)/admin_*'

; allow UserProfile controller's view_detail action, just an example
url[] = 'UserProfile/view_detail'

[zone:general-user]
; allow all actions except admin_ actions
url[] = '(\w+)/(?!admin_)*'

; allow all plugin actions except admin_ actions
url[] = '(\w+)/(\w+)/(?!admin_)*'