1
votes

Cakephp Pagination rendering issue. I am using cakephp 2.0.6. When i try to render a page from other action its fine. But when i try to go to next page the problem starts

I have the following function

   public function admin_index() 
   {
       //Function listing 
   }

The same function needed for all type of users(support,employee etc). So I used the setAction method as follows

public function support_index() 
   {
        $this->setAction('admin_index');
        $this->render('admin_index');
   }

And my Pagination code is as follows :

    echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));

    echo $this->Paginator->numbers(array('separator' => ''));

    echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));

But when I try to go next page the URL as follows

http://www.example.com/support/users/admin_index/page:2
http://www.example.com/employee/users/admin_index/page:2

But the following output needs to come :

http://www.example.com/support/users/index/page:2
http://www.example.com/employee/users/index/page:2

The Problem is $this->setAction('admin_index'); i think.. any one helps appreciated

2

2 Answers

1
votes

I made the changes in the following file lib/Cake/Controller/Controller.php

The changes made in setAction method it works well now. especially the problem is in 2.0.6

public function setAction($action) {
    $this->request->params['action'] = $action; //Commented this Line 
    $this->view = $action; //Commented this Line


    $this->request->action = $action; // Added this Line
    $args = func_get_args();
    unset($args[0]);
    return call_user_func_array(array(&$this, $action), $args);

}
0
votes

setAction

Internally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect();

Redirection is a different terminology, actually when it redirect to another action then it will become that action automatically that's why paginate will does not change the url.

Instead of using setAction you can use following code:

public function admin_index() 
{
    $this->set('data',$this->__paginatedata());

}

function __paginatedata(){
    $this->paginate = array('limit'=>5);
    $this->Model->recursive = 0;
    return $this->paginate();
}

public function support_index() 
{
    $this->set('data',$this->__paginatedata());
    $this->render('admin_index');
}