20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

class PostController extends CController<br />

{<br />

......<br />

public function filters()<br />

{<br />

return array(<br />

'accessControl',<br />

);<br />

}<br />

}<br />

In the above, we specify that the access control filter should be applied to every action of<br />

PostController. The detailed authorization rules used by the filter are specified by<br />

overriding CController::accessRules in the controller class.<br />

class PostController extends CController<br />

{<br />

......<br />

public function accessRules()<br />

{<br />

return array(<br />

array('deny',<br />

'actions'=>array('create', 'edit'),<br />

'users'=>array('?'),<br />

),<br />

array('allow',<br />

'actions'=>array('delete'),<br />

'roles'=>array('admin'),<br />

),<br />

array('deny',<br />

'actions'=>array('delete'),<br />

'users'=>array('*'),<br />

),<br />

);<br />

}<br />

}<br />

The above code specifies three rules, each represented as an array. The first element of<br />

the array is either 'allow' or 'deny' and the other name-value pairs specify the pattern<br />

parameters of the rule. The rules defined above are interpreted as follows: the create and<br />

edit actions cannot be executed by anonymous users; the delete action can be executed<br />

by users with admin role; and the delete action cannot be executed by anyone.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!