user2356747
user2356747

Reputation: 65

How to maintain a variable in the url which is customized in cakephp?

What im trying to do here is maintain the variable 42 all throughout all pagination urls. I want my url to change from this

/exams/take/42/page:2

to this

/exams/take/42/items/2

Again,the number 42 is the variable..and the number 2 is the page number..Thanks.

UPDATE :

routes.php
 Router::connect('/examinations/take/:id/page/:page', 
array('controller' => 'examinations', 'action' => 'take'),
array(
    'pass' => array('id', 'page'),
    'id' => '[0-9]+',
    'page' => '[0-9]+'
    )
);

in the view/take

$this->Paginator->options(array('url' => $this->passedArgs));

AppController.php

public function beforeFilter(){
    if (isset($this->request->params['page'])) {
        $this->request->params['named']['page'] =                           $this->request->params['page']; 
    }
}

ive tried this ..but the generated url is the same,/examinations/take/42/page:2 ,when i click the next and prev links..

Upvotes: 1

Views: 236

Answers (2)

liyakat
liyakat

Reputation: 11853

yes you can do it with the use of custom routing. for more undrestanding you can see cakephp manual to manage custom routing in pagination

http://book.cakephp.org/2.0/en/development/routing.html

below will be your

e.g.

And by adding this route:

Router::connect('/:id/page/:page', 
    array('controller' => 'examinations', 'action' => 'take'),
    array(
        'pass' => array('id', 'page'),
        'id' => '[0-9]+',
        'page' => '[0-9]+'
        )
);

and i does not work you can refer link

Upvotes: 1

Vinod Patidar
Vinod Patidar

Reputation: 685

You've to define custom routes:

http://book.cakephp.org/2.0/en/development/routing.html

Example as below:

    Router::connect(
      '/exams/take/:id/items/:number',
      array('controller' => 'exams', 'action' => 'take'),
      array('pass' => array('id', 'number'))
    );

Also you can get more information from below url try this: http://www.sakic.net/blog/changing-cakephp-pagination-urls

Upvotes: 2

Related Questions