回到与离开分页时相同的页面

时间:2014-10-25 02:46:13

标签: php cakephp

如何返回使用paginator并让它显示特定页面的记录的列表视图?

For example
1)I am at list_view which displays a list of records. 
2) I go to page 2
3) I click a record and get taken to another page to see the details of this record
4) I click back link and I am back at the list view BUT I am on page 1 and 
 I want to be on page 2

回到列表视图的当前方法是什么,当你离开它时在同一页面上?我需要会话变量吗?

//controller    list view 
 $this->Paginator->settings = array(
             'conditions' => array(
             'TutorRequest.tutor_id' => $tutorId, 
             'TutorRequest.type' => 'meeting'),
             'limit' => 2  );

            $meetings = $this->Paginator->paginate('TutorRequest');
            $this->set('meetings', $meetings);

 //view of 1 item and want to go back to the list view
 echo  ..'Back', array(
         'controller' => 'lessons',  'action' => 'dashboard4', //back to same page  

2 个答案:

答案 0 :(得分:1)

只需转到记录详细信息页面,通过网址发送您所在的页面:“detailsPage.php?id = 123& page = 2”并在那里构建后退按钮:“recordsPage.php?page = 2”

答案 1 :(得分:1)

让我们说你有联系人,然后你转到第2页。在你的联系人控制器中你有一个名为view的方法。在此方法中,您执行以下操作

public function view($id){

   //some code
   $this->set('refer', $this->referer());
}

在您看来,您创建了一个链接

echo $this->Html->link(__('Back'), $refer);

或者你可以这样做

echo $this->Html->link(__('Back'), $this->request->referer());

检查一下: http://book.cakephp.org/2.0/en/controllers/request-response.html#CakeRequest::referer