Hi,
I have this code …
$auth = Yii::app()->authManager;
// Create roles
$role["standard"] = $auth->createRole("standard");
$role["accountholder"] = $auth->createRole("accountHolder");
// Create tasks / operations and assigns operations to tasks
$task["user"] = $auth->createTask("userManagement", "Manages the users");
$auth->createOperation("editSubUser");
$auth->createOperation("deleteSubUser");
$task["user"]->addChild("editSubUser");
$task["user"]->addChild("deleteSubUser");
// Add tasks to roles
$role["accountHolder"]->addChild("userManagement");
$auth->save();
everything works except this …
$role["accountHolder"]->addChild("userManagement");
I get this error …
Fatal error: Call to a member function addChild() on a non-object in /Applications/MAMP/htdocs/projects/DevelopmentProject/DevelopmentApp/protected/controllers/SiteController.php on line 33
PLEASE NOTE …
I am running this code in a controller method as I do not know the proper place to put it.
Any help chaps?
Strange … it works now, I used this code.
$auth = Yii::app()->authManager;
// Create roles
$role["standard"] = $auth->createRole("standard");
//$role["accountholder"] = $auth->createRole("accountHolder");
// Create tasks / operations and assigns operations to tasks
$task["user"] = $auth->createTask("userManagement", "Manages the users");
$auth->createOperation("editSubUser");
$auth->createOperation("deleteSubUser");
$task["user"]->addChild("editSubUser");
$task["user"]->addChild("deleteSubUser");
// Add tasks to roles
//$role["accountHolder"]->addChild("userManagement");
$role = $auth->createRole("accountHolder");
$role->addChild("userManagement");
$auth->save();
Please spot the difference, anyone?
Also I still need to know where to put the code, as I do not think in a controllers method is very good.
Also can someone please explain the difference between tasks and operations and whether I am using them correctly.
To me, it there does not seem much point in having both tasks and operations so maybe someone can shed some light on this.
phtamas
(Phtamas)
April 1, 2011, 3:49pm
3
JamesBarnsley:
Hi,
I have this code …
$auth = Yii::app()->authManager;
// Create roles
$role["standard"] = $auth->createRole("standard");
$role["accountholder"] = $auth->createRole("accountHolder");
// Create tasks / operations and assigns operations to tasks
$task["user"] = $auth->createTask("userManagement", "Manages the users");
$auth->createOperation("editSubUser");
$auth->createOperation("deleteSubUser");
$task["user"]->addChild("editSubUser");
$task["user"]->addChild("deleteSubUser");
// Add tasks to roles
$role["accountHolder"]->addChild("userManagement");
$auth->save();
everything works except this …
$role["accountHolder"]->addChild("userManagement");
I get this error …
Fatal error: Call to a member function addChild() on a non-object in /Applications/MAMP/htdocs/projects/DevelopmentProject/DevelopmentApp/protected/controllers/SiteController.php on line 33
PLEASE NOTE …
I am running this code in a controller method as I do not know the proper place to put it.
Any help chaps?
[font=“Times”][size=“2”][font=“arial, verdana, tahoma, sans-serif”][size=“2”]There’s a typing error in your code:
$role["accountholder"] = $auth->createRole("accountHolder");
[/size][/font][/size][/font]
[size="3"] [/size]
[font="Times"][size="2"] [font="arial, verdana, tahoma, sans-serif"]should be[/font][/size][/font]
[size="3"] [/size]
[font="Times"][size="2"][font="arial, verdana, tahoma, sans-serif"]
$role["accountHolder"] = $auth->createRole("accountHolder");
[/font][/size][/font]
[size="3"] [/size]
[size="3"][size="2"]with capital "H".[/size][/size]