<?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; } } }