Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Created November 14, 2011 11:39
Show Gist options
  • Save naiquevin/1363777 to your computer and use it in GitHub Desktop.
Save naiquevin/1363777 to your computer and use it in GitHub Desktop.
Code Examples for Acl in Kodelearn http://github.com/kodeplay/kodelearn
<?php
// defining resource-levels as arrays
return array(
'exam' => array(
'levels' => array(
'view',
'create',
'edit',
'delete'
)
),
);
<?php
// each module holds its own acl.php file
// code in application/config/acl.php
return array(
'course' => array(
'levels' => array(
'view',
'create',
'edit',
'delete',
'join'
)
),
);
// code in modules/exam/config/acl.php
return array(
'exam' => array(
'levels' => array(
'view',
'create',
'edit',
'delete'
)
),
);
<?php
// specifying default levels
// code in application/config/acl.php
return array(
'default' => array(
'view',
'create',
'edit',
'delete'
),
'course' => array(
'levels' => array(
'join' , // all default levels are inherited
)
),
);
<?php
// level inheritance can be disabled if needed
return array(
'messaging' => array(
'inherit_default' => false,
'levels' => array(
'send'
),
),
);
<?php
// code in before method of a controller
$acl = Acl::instance();
if (!$acl->has_access($resource)) {
Request::current()->redirect('error/access_denied');
}
// code in a view file
// checks if the user is authorized to upload a document and show the
// upload button accordingly
if(Acl::instance()->is_allowed('document_upload')) {
echo HTML::anchor('document/upload', 'Upload', array('class' => 'dib button round5')); ?>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment