Hello friends
I’m using Yii 1.1.4
I created the file RbacCommand.php:
<?php
class RbacCommand extends CConsoleCommand
{
private $authManager;
public function getHelp()
{
return <<<EOD
USAGE
rbac
DESCRIPTION
This command generates an initial RBAC authorization hierarchy.
EOD;
}
/*
Execute the action
@param array command line paramenters specific for this command
*/
public function run($args)
{
//ensure that an authManager is defined as this is mandatory for creating an auth heirarchy
if(($this->_authManager=Yii::app()->authManager)===null)
{
echo "Error: an authorization manager, named, 'authManager' must be configured to use this command.\n";
echo "If you already added 'authManager' component in application configuration, \n";
echo "please quit an re-enter the yiic shell.\n";
return;
}
//provide the oportunity for the use to abort the request
echo "create, read, update and delete user,\n";
echo "create, read, update and delete project,\n";
echo "create, read, update and delete issue,\n";
echo "Would you like to continue?[Yes][No] ";
//check the input from the user and continue if they indicate yes ti the above question
if(!strncasecmp(trim(fgets(STDIN)), 'y', 1))
{
//first we need to remove all operations, roles, child relationships andassignments
$this->_authManager->clearAll();
//create the lowest leveloperations for users
$this->_authManager->createOperation("createUser","create a new user");
$this->_authManager->createOperation("readUser", "read user profile information");
$this->_authManager->createOperation("updateUser", "update a users information");
$this->_authManager->createOperation("deleteUser", "remove a user from a project");
//create the lowest level operations for projects
$this->_authManager->createOperation("createProject", "create a new project");
$this->_authManager->createOperation("readProject", "read project information");
$this->_authManager->createOperation("updateProject", "update project information");
$this->_authManager->createOperation("deleteProject", "delete a project");
//create the lwest level operations for issues
$this->_authManager->createOperation("createIssue", "create a new issues");
$this->_authManager->createOperation("readIssue", "read issue information");
$this->_authManager->createOperation("updateIssue", "update issue information");
$this->_authManager->createOperation("deleteIssue", "delete an issue from a project");
//create the reader role and add the appropriate permissions as children to this role
$role=$this->_authManager->createRole("reader");
$role->addChild("readUser");
$role->addChild("readProject");
$role->addChild("readIssue");
//create the member role, and add the appropriate permissions, as well as both the reader role itself, as children
$role->$this->_authManager->createRole("member");
$role->addChild("reader");
$role->addChild("createIssue");
$role->addChild("updateIssue");
$role->addChild("deleteIssue");
//create the owner role, and add the appropriate permissions, as well as both the reader and member roles as children
$role->$this->_authManager->createRole("owner");
$role->addChild("reader");
$role->addChild("member");
$role->addChild("createUser");
$role->addChild("updateUser");
$role->addChild("deleteUser");
$role->addChild("createProject");
$role->addChild("updateProject");
$role->addChild("deleteProject");
//provide a messege indicating success
echo "Authorization hierarchy successfully generated";
}
}
}
?>
But when I execute on the shell there is a error:
[b]
alexandre@alexandre-desktop:/var/www/trackstar$ /var/www/yii/framework/yiic shell
Yii Interactive Tool v1.1 (based on Yii v1.1.4)
Please type ‘help’ for help. Type ‘exit’ to quit.
>> rbac
PHP Parse error: syntax error, unexpected $end in /var/www/trackstar/protected/commands/shell/RbacCommand.php on line 96
[/b]
This the line 96:
?>
After this line:
return <<<EOD
whole code becomes comment
Is Where the error?
If a Remove the code:
public function getHelp()
{
return <<<EOD
USAGE
rbac
DESCRIPTION
This command generates an initial RBAC authorization hierarchy.
EOD;
}
I have this error:
[b]
alexandre@alexandre-desktop:/var/www/trackstar$ /var/www/yii/framework/yiic shell
Yii Interactive Tool v1.1 (based on Yii v1.1.4)
Please type ‘help’ for help. Type ‘exit’ to quit.
>> rbac
exception ‘CException’ with message ‘Property “RbacCommand._authManager” is not defined.’ in /var/www/yii/framework/base/CComponent.php:173
Stack trace:
#0 /var/www/trackstar/protected/commands/shell/RbacCommand.php(25): CComponent->__set(’_authManager’, Object(CDbAuthManager))
#1 /var/www/yii/framework/cli/commands/ShellCommand.php(147): RbacCommand->run(Array)
#2 /var/www/yii/framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell()
#3 /var/www/yii/framework/console/CConsoleCommandRunner.php(62): ShellCommand->run(Array)
#4 /var/www/yii/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)
#5 /var/www/yii/framework/base/CApplication.php(135): CConsoleApplication->processRequest()
#6 /var/www/yii/framework/yiic.php(33): CApplication->run()
#7 /var/www/yii/framework/yiic(15): require_once(’/var/www/yii/fr…’)
#8 {main}
>>
[/b]
sorry if my English is bad I’m from Brazil