I want to use the router of cake for friendly urls. My urls are of this type:
http://domain/some_text/categories/view/4/5/6
http://domain/other_text/articles/read/new-stuff
http://domain/xyz_text/charts/list/latest/10
The basic idea is that the first part of the url (some_text, other_text,开发者_高级运维 xyz_text)
will be forwarded as a parameter to the action, but not as a named parameter.
- Can I build such route in a single route?
- Yes/No - How?
- Is it the way to achieve that goal?
- How do I create a link to such route, using
HtmlHelper:link()
method? (some tests gave mehttp://domain/Controller/action/params../some_name:some_text
...)
You can do something like this, but you will need to build one for each controller. Here is the example for the categories controller you listed in your question:
http://domain/some_text/categories/view/4/5/6
Router::connect(
'/:pagevar/:controller/:action/*',
array(
'controller' => 'categories',
'action' => 'view',
),
array(
'pass' => 'pagevar'
)
);
Then to access the 'some_text' var, you can just reference it through the params:
$this->params['pagevar']
I'm not sure this is exactly what you want to hear, but it may give you some ideas where to build from.
精彩评论