Skip to content

Instantly share code, notes, and snippets.

@rinatio
Forked from anonymous/SetRoleCommand
Created December 12, 2012 20:21
Show Gist options
  • Save rinatio/4271221 to your computer and use it in GitHub Desktop.
Save rinatio/4271221 to your computer and use it in GitHub Desktop.
<?php
class SetRoleCommand extends CConsoleCommand
{
public function actionIndex($role, $userId)
{
$auth = Yii::app()->authManager;
$roles = $auth->getRoles();
if (!array_key_exists($role, $roles)) {
$auth->createRole($role);
}
$auth->assign($role, $userId);
$auth->save();
if ($auth->checkAccess($role, $userId)) {
echo "Role assigned successfully\n";
} else {
return 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment