O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
$auth=<strong>Yii</strong>::app()->authManager;<br />
$auth->createOperation('createPost','create a post');<br />
$auth->createOperation('readPost','read a post');<br />
$auth->createOperation('updatePost','update a post');<br />
$auth->createOperation('deletePost','delete a post');<br />
$bizRule='return <strong>Yii</strong>::app()->user->id==$params["post"]->authID;';<br />
$task=$auth->createTask('updateOwnPost','update a post by author himself',<br />
$bizRule);<br />
$task->addChild('updatePost');<br />
$role=$auth->createRole('reader');<br />
$role->addChild('readPost');<br />
$role=$auth->createRole('author');<br />
$role->addChild('reader');<br />
$role->addChild('createPost');<br />
$role->addChild('updateOwnPost');<br />
$role=$auth->createRole('editor');<br />
$role->addChild('reader');<br />
$role->addChild('updatePost');<br />
$role=$auth->createRole('admin');<br />
$role->addChild('editor');<br />
$role->addChild('author');<br />
$role->addChild('deletePost');<br />
$auth->assign('reader','readerA');<br />
$auth->assign('author','authorB');<br />
$auth->assign('editor','editorC');<br />
$auth->assign('admin','adminD');<br />
Once we have established this hierarchy, the authManager component (e.g.<br />
CPhpAuthManager, CDbAuthManager) will load the authorization items automatically.<br />
Therefore, we only need to run the above code one time, and NOT for every request.<br />
Info: While the above example looks long and tedious, it is mainly for demonstrative<br />
purpose. Developers will usually need to develop some administrative user interfaces<br />
so that end users can use to establish an authorization hierarchy more intuitively.