O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
array(<br />
'//' => '/<br />
',<br />
'/' => '/read',<br />
's' => '/list',<br />
)<br />
In the above, we use two named parameters in the route part of the rules: _c and _a. The<br />
former matches a controller ID to be either post or comment, while the latter matches an<br />
action ID to be create, update or delete. You may name the parameters differently as long<br />
as they <strong>do</strong> not conflict with GET parameters that may appear in URLs.<br />
Using the aboving rules, the URL /index.php/post/123/create would be parsed as the route<br />
post/create with GET parameter id=123. And given the route comment/list and GET<br />
parameter page=2, we can create a URL /index.php/comments?page=2.<br />
Parameterizing Hostnames<br />
Starting from version 1.0.11, it is also possible to include hostname into the rules for<br />
parsing and creating URLs. One may extract part of the hostname to be a GET parameter.<br />
For example, the URL http://admin.example.com/en/profile may be parsed into GET<br />
parameters user=admin and lang=en. On the other hand, rules with hostname may also<br />
be used to create URLs with paratermized hostnames.<br />
In order to use parameterized hostnames, simply declare URL rules with host info, e.g.:<br />
array(<br />
)<br />
'http://.example.com//profile' => 'user/profile',<br />
The above example says that the first segment in the hostname should be treated as user<br />
parameter while the first segment in the path info should be lang parameter. The rule<br />
corresponds to the user/profile route.<br />
Note that CUrlManager::showScriptName will not take effect when a URL is being created<br />
using a rule with parameterized hostname.<br />
Also note that the rule with parameterized hostname should NOT contain the sub-folder if<br />
the application is under a sub-folder of the Web root. For example, if the application is<br />
under http://www.example.com/sandbox/blog, then we should still use the same URL rule<br />
as described above without the sub-folder sandbox/blog.<br />
Hiding index.php<br />
There is one more thing that we can <strong>do</strong> to further clean our URLs, i.e., hiding the entry<br />
script index.php in the URL. This requires us to configure the Web server as well as the<br />
urlManager application component.