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 rules are specified as an array of pattern-route pairs, each corresponding to a single<br />

rule. The pattern of a rule is a string used to match the path info part of URLs. And the<br />

route of a rule should refer to a valid controller route.<br />

Besides the above pattern-route format, a rule may also be specified with customized<br />

options, like the following:<br />

'pattern1'=>array('route1', 'urlSuffix'=>'.xml', 'caseSensitive'=>false)<br />

In the above, the array contains a list of customized options. As of version <strong>1.1</strong>.0, the<br />

following options are available:<br />

• urlSuffix: the URL suffix used specifically for this rule. Defaults to null, meaning using<br />

the value ofCUrlManager::urlSuffix.<br />

• caseSensitive: whether this rule is case sensitive. Defaults to null, meaning using the<br />

value ofCUrlManager::caseSensitive.<br />

• defaultParams: the default GET parameters (name=>value) that this rule provides.<br />

When this rule is used to parse the incoming request, the values declared in this<br />

property will be injected into $_GET.<br />

• matchValue: whether the GET parameter values should match the corresponding<br />

sub-patterns in the rule when creating a URL. Defaults to null, meaning using the<br />

value of CUrlManager::matchValue. If this property is false, it means a rule will be<br />

used for creating a URL if its route and parameter names match the given ones. If<br />

this property is set true, then the given parameter values must also match the<br />

corresponding parameter sub-patterns. Note that setting this property to true will<br />

degrade performance.<br />

Using Named Parameters<br />

A rule can be associated with a few GET parameters. These GET parameters appear in<br />

the rule's pattern as special tokens in the following format:<br />

&lt;ParamName:ParamPattern&gt;<br />

Where ParamName specifies the name of a GET parameter, and the optional<br />

ParamPattern specifies the regular expression that should be used to match the value of<br />

the GET parameter. In case whenParamPattern is omitted, it means the parameter should<br />

match any characters except the slash /. When creating a URL, these parameter tokens<br />

will be replaced with the corresponding parameter values; when parsing a URL, the<br />

corresponding GET parameters will be populated with the parsed results.<br />

Let's use some examples to explain how URL rules work. We assume that our rule set<br />

consists of three rules:

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

Saved successfully!

Ooh no, something went wrong!