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.

Tópicos Especiais<br />

Gerenciamento de URL<br />

Complete URL management for a Web application involves two aspects. First, when a<br />

user request comes in terms of a URL, the application needs to parse it into<br />

understandable parameters. Second, the application needs to provide a way of creating<br />

URLs so that the created URLs can be understood by the application. For a <strong>Yii</strong> application,<br />

these are accomplished with the help of CUrlManager.<br />

Creating URLs<br />

Although URLs can be hardcoded in controller views, it is often more flexible to create<br />

them dynamically:<br />

$url=$this->createUrl($route,$params);<br />

Where $this refers to the controller instance; $route specifies the route of the request; and<br />

$params is a list of GET parameters to be appended to the URL.<br />

By default, URLs created by createUrl is in the so-called get format. For example, given<br />

$route='post/read' and $params=array('id'=>100), we would obtain the following URL:<br />

/index.php?r=post/read&id=100<br />

Where parameters appear in the query string as a list of Name=Value concatenated with<br />

the ampersand characters, and the r parameter specifies the request route. This URL<br />

format is not very user-friendly because it requires several non-word characters.<br />

We could make the above URL look cleaner and more self-explanatory by using the socalled<br />

path format which eliminates the query string and puts the GET parameters into the<br />

path info part of URL:<br />

/index.php/post/read/id/100<br />

To change the URL format, we should configure the urlManager application component so<br />

that createUrl can automatically switch to the new format and the application can properly<br />

understand the new URLs:

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

Saved successfully!

Ooh no, something went wrong!