0
votes

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...)
1

1 Answers

1
votes

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.