我在CakePHP页面上使用分页并且它运行良好,但是我在一个控制器文件中有不同函数生成的几个页面,这是一个麻烦的问题。
让我们假设我有两个包含数百个条目的表,我的分页器在一个页面上划分并显示15个条目:
public $paginate = array( 'Table1' => Array( 'order' => array('Table1.id' => 'desc'), 'limit' => 15 ), 'Table2' => Array( 'order' => array('Table2.id' => 'asc'), 'limit' => 15 ) );和此控制器文件中的函数:
public function showTable1() { $this->set('table', $this->paginate('Table1')); } public function showTable2() { $this->set('table', $this->paginate('Table2)); }当我在显示“表1”时转到下一页时,我转到下一页,它运行良好。 但是当我用同一个控制器文件中的另一个函数生成的“表2”打开另一个页面时,遗憾的是它也进入了第二页。
我该怎么做才能拥有不同的“页面指标”? 我的意思是,当我进入“表1”的第三页时,当我转到“表2”时,我不想进入第三页。
提前致谢。 我希望我能清楚地表达我的问题。
I am using pagination on my CakePHP page and it works well, but I have a few pages generated by different functions in one controller file and there is an cumbersome issue.
Let's assume I've got two tables with hundreds of entries, which my paginators divide and display 15 of entries on one page:
public $paginate = array( 'Table1' => Array( 'order' => array('Table1.id' => 'desc'), 'limit' => 15 ), 'Table2' => Array( 'order' => array('Table2.id' => 'asc'), 'limit' => 15 ) );And functions in this controller file:
public function showTable1() { $this->set('table', $this->paginate('Table1')); } public function showTable2() { $this->set('table', $this->paginate('Table2)); }When I go to the next page while displaying "Table 1", I go to the next page and it works well. But when I open another page with "Table 2" generated by another function from the same controller file, it unfortunately also goes to the second page.
What should I do to have different "pages indicators"? I mean, when I go to the third page on "Table 1", I don't want to go to the third page when I go to "Table 2".
Thanks in advance. I hope I presented my problem clearly.
最满意答案
而不是在控制器顶部设置分页选项,尝试删除该public $paginate并设置action中的所有选项,如下所示(并以类似的方式进行第二个操作)
public function showTable1() { $options = array( 'conditions' => array( 'Table1.id' => whatever ), 'fields' => array( 'Table1.id' ), 'order' => array( 'Table1.id' => 'DESC' ), 'limit' => 15 ); $this->Paginator->settings = $options; $table = $this->Paginator->paginate('Table1'); $this->set(compact('table')); }instead of setting the pagination options on the top of the controller, try deleting that public $paginate and setting all the options inside action, like this (and in the similar way for the second action)
public function showTable1() { $options = array( 'conditions' => array( 'Table1.id' => whatever ), 'fields' => array( 'Table1.id' ), 'order' => array( 'Table1.id' => 'DESC' ), 'limit' => 15 ); $this->Paginator->settings = $options; $table = $this->Paginator->paginate('Table1'); $this->set(compact('table')); }更多推荐
发布评论