views:

66

answers:

1

Hi, In my Cake application I have a controller "completed_projects". Its index action takes no arguments and lists some projects. Different pages can be accessed by example.com/completed_projects/index/page:23 etc.

I want to make the url's like this:

example.com/portfolio/page23

Obviously I need to make some routes for this. I've tried many of them like:

Router::connect('/portfolio/page:num', array('controller' => 'completed_projects', 'action' => 'index'), array('pass'=>'page:num', 'num'=>'[0-9]+'));

and also:

Router::connect('/portfolio/:page:num', array('controller' => 'completed_projects', 'action' => 'index'), array('named'=>'num', 'page'=>'page', 'num'=>'[0-9]+'));

I also tried modifying them again and again but none of them works well.

I am using CakePHP 1.3. Any help will be appreciated.

+1  A: 
Router::connect('/portfolio/page:page_num',
    array('controller'=>'completed_projects', 'action'=>'index'),
    array('page_num'=>'[\d]+')
);

In your controller, access page_num with:

$this->params['page_num'];
Oscar
This passes page_num (like 23) to the action but I want that a named-parameter be passed like page:2 is passed. Thanks for considering to help anyway.
Muhammad Yasir
Sorry, updated the answer to fit your needs, hopefully :)
Oscar
Thanks again Oscar. Could you please elaborate how this (or any) variable be used for pagination? Getting just a passed variable in controller is not requirement. I want it to be named argument (like page:33) so that it can be used for pagination. Is it even possible?
Muhammad Yasir
Ah, you meant that you want to change the way that the normal paginator URLs look like?
Oscar
You might want to take a look at this in that case, as far as I know there is no cleaner way to do this: http://stackoverflow.com/questions/1078558/cakephp-pagination-how-to-remove-page-from-url-for-better-seo-cleaner-url
Oscar
Perfect! This solves my problem. Thanks :)
Muhammad Yasir