Created
November 14, 2011 11:39
-
-
Save naiquevin/1363777 to your computer and use it in GitHub Desktop.
Code Examples for Acl in Kodelearn http://github.com/kodeplay/kodelearn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// defining resource-levels as arrays | |
return array( | |
'exam' => array( | |
'levels' => array( | |
'view', | |
'create', | |
'edit', | |
'delete' | |
) | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' | |
) | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
) | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// level inheritance can be disabled if needed | |
return array( | |
'messaging' => array( | |
'inherit_default' => false, | |
'levels' => array( | |
'send' | |
), | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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