1
votes

i m new in cakephp

first time load url like this

http://domain.com/td/city

http://domain.com/td/ is a static

city is a dynamic

in pagination the url display like

http://domain.com/controller/action/city/page:2

but i m want url like this in pagination

http://domain.com/td/city/2

please help me to solve this

UPDATE: i don't want "controller", "action" and "page:" keyword in url

my routes define is

Router::Connect('/td/:city/*', 
    array('controller' => 'properties', 'action' => 'citybasedproperties' ),
    array('city' => '[a-z0-9-]+', // regex again to ensure a valid city or 404
          'pass' => array('city') // I just want to pass through city to my controller
));  
2

2 Answers

3
votes

http://www.website.com/post/page:2

we would like to change it to

http://www.website.com/post/page/2

1. /app/Config/routes.php Add or modify the existing route to

    Router::connect('/post/page/:page', array(
     'controller' => 'post',
     'action' => 'index'
    ), array(
    'pass' => array(
        'page'
    ),
     'page' => '[\d]+'
   ));

2. /app/Controller/PostsController.php

Add or modify the existing controller to

public function index($page = 1) {
// ...
$this->request->params['named']['page'] = $page;
// ...
}

3. /app/View/Posts/index.ctp

Add or modify the existing view to

$paginator->options(array(
   'url'=> array(
   'controller' => 'post',
   'action' => 'index'
)));

You should read this post SEO Friendly URL in CakePHP Pagination

0
votes

Read the Routing chapter of the documentation it covers that case with an example and explains how routing in CakePHP works. I suggest you to actually read and try to understand the whole page and not just copy and paste the examples.