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.

The access rules are evaluated one by one in the order they are specified. The first rule<br />

that matches the current pattern (e.g. username, roles, client IP, address) determines the<br />

authorization result. If this rule is an allow rule, the action can be executed; if it is a deny<br />

rule, the action cannot be executed; if none of the rules matches the context, the action<br />

can still be executed.<br />

Tip: To ensure an action <strong>do</strong>es not get executed under certain contexts, it is beneficial<br />

to always specify a matching-all deny rule at the end of rule set, like the following:<br />

return array(<br />

);<br />

// ... other rules...<br />

// the following rule denies 'delete' action for all contexts<br />

array('deny',<br />

),<br />

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

The reason for this rule is because if none of the rules matches a context, then the<br />

action will continue to be executed.<br />

An access rule can match the following context parameters:<br />

• actions: specifies which actions this rule matches. This should be an array of action<br />

IDs. The comparison is case-insensitive.<br />

• controllers: specifies which controllers this rule matches. This should be an array of<br />

controller IDs. The comparison is case-insensitive. This option has been available<br />

since version 1.0.4.<br />

• users: specifies which users this rule matches. The current user's name is used for<br />

matching. The comparison is case-insensitive. Three special characters can be used<br />

here:<br />

• *: any user, including both anonymous and authenticated users.<br />

• ?: anonymous users.<br />

• @: authenticated users.<br />

• roles: specifies which roles that this rule matches. This makes use of the role-based<br />

access controlfeature to be described in the next subsection. In particular, the rule is<br />

applied if CWebUser::checkAccess returns true for one of the roles. Note, you should<br />

mainly use roles in an allowrule because by definition, a role represents a permission<br />

to <strong>do</strong> something. Also note, although we use the term roles here, its value can<br />

actually be any auth item, including roles, tasks and operations.<br />

• ips: specifies which client IP addresses this rule matches.<br />

• verbs: specifies which request types (e.g. GET, POST) this rule matches. The<br />

comparison is case-insensitive.<br />

• expression: specifies a PHP expression whose value indicates whether this rule<br />

matches. In the expression, you can use variable $user which refers to <strong>Yii</strong>::app()-<br />

>user. This option has been available since version 1.0.3.<br />

Handling Authorization Result

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

Saved successfully!

Ooh no, something went wrong!