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.

array(<br />

......<br />

'components'=>array(<br />

......<br />

'urlManager'=>array(<br />

'urlFormat'=>'path',<br />

),<br />

),<br />

);<br />

Note that we <strong>do</strong> not need to specify the class of the urlManager component because it is<br />

pre-declared asCUrlManager in CWebApplication.<br />

Tip: The URL generated by the createUrl method is a relative one. In order to get an<br />

absolute URL, we can prefix it with <strong>Yii</strong>::app()->request->hostInfo, or call<br />

createAbsoluteUrl.<br />

User-friendly URLs<br />

When path is used as the URL format, we can specify some URL rules to make our URLs<br />

even more user-friendly. For example, we can generate a URL as short as /post/100,<br />

instead of the lengthy/index.php/post/read/id/100. URL rules are used by CUrlManager for<br />

both URL creation and parsing purposes.<br />

To specify URL rules, we need to configure the rules property of the urlManager<br />

application component:<br />

array(<br />

......<br />

'components'=>array(<br />

......<br />

'urlManager'=>array(<br />

'urlFormat'=>'path',<br />

'rules'=>array(<br />

'pattern1'=>'route1',<br />

'pattern2'=>'route2',<br />

'pattern3'=>'route3',<br />

),<br />

),<br />

),<br />

);

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

Saved successfully!

Ooh no, something went wrong!