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/ */
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_)*'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.