开发者

cakePhp routing, how do I create a route that ...?

开发者 https://www.devze.com 2023-03-06 10:50 出处:网络
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

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.

  1. Can I build such route in a single route?
  2. Yes/No - How?
  3. Is it the way to achieve that goal?
  4. How do I create a link to such route, using HtmlHelper:link() method? (some tests gave me http://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.

0

精彩评论

暂无评论...
验证码 换一张
取 消