<?php
function search() {
$this->Table->recursive = 0;
if ($this->data['Table']['search_text']) {
$this->set('Table',
$this->paginate('Table', array('or' => array('Table.field LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_2 LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_3 LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_4 LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_5 LIKE' => '%' .
$this->data['Table']['search_text'] . '%'))));
}
else {
$this->set('Tables', $this->paginate());
}
}
?>
如何对方法search()的结果进行分页?
答案 0 :(得分:0)
您已将其分页,变量Tables
现在将保持分页。
我建议您查看http://book.cakephp.org/view/1231/Pagination以进行分页。
如果您特别希望search()
方法返回您可以执行的分页结果:
<?php
function search() {
$data = null;
$this->Table->recursive = 0;
if ($this->data['Table']['search_text']) {
$data =
$this->paginate('Table', array('or' => array('Table.field LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_2 LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_3 LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_4 LIKE' => '%' .
$this->data['Table']['search_text'] . '%', 'Table.field_5 LIKE' => '%' .
$this->data['Table']['search_text'] . '%')));
}
else {
$data = $this->paginate();
}
return $data;
}
?>
搜索的返回值现在将保存分页的结果。