开发者

How to paginate search results

<?php   
  function search() {
    $this->Table->recursive = 0;
    if ($this->data['Table']['search_text']) {
        $this->set('Table', 
        $this->paginate('Table', array('or' => array('Table.fi开发者_JAVA技巧eld 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());
    }
  }
?>

How can I paginate the results of the method search() ?


You have paginated it, the variable Tables will now hold the pagination.

I would recommend looking at http://book.cakephp.org/view/1231/Pagination to do with pagination.

If you specifically wanted the search() method to return the result of the pagination you could do:

<?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;
  }
?>

The return value of search will now hold the result of the pagination.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜