在cakephp中分页搜索结果

时间:2014-01-07 22:25:06

标签: php cakephp pagination cakephp-1.3

我有内置搜索的CakePHP 1.3.5站点。问题是搜索结果太多而无法在一个屏幕上显示,搜索过程需要花费大量时间(超过30秒)。

在控制器中我有:

public function search() {
    $regions = $this->RealEstate->Region->find('list');
    $realEstateCategories = $this->RealEstate->realEstateCategories();
    $realEstateTypes = $this->RealEstate->RealEstateType->find('list');
    $this->set(compact('regions', 'realEstateCategories', 'realEstateTypes'));
}

public function results($local = false) {
    if (!$this->RequestHandler->isAjax()) {
        $this->cakeError('error404');
    }
    if ($local) {
        $params = $this->_myEstatesCriteria();
        $this->set(compact('local'));
        $realEstates = $this->RealEstate->search($this->data, $params['conditions']);
    } else {
        $realEstates = $this->RealEstate->search($this->data);
    }
    $this->layout = '';
    $this->set(compact('realEstates'));
}

我在条件设置限制并尝试了这个,但没有结果。

$this->paginate = $this->RealEstate->search($this->data);
$realEstates = $this->paginate();

1 个答案:

答案 0 :(得分:1)

检查the official documentation about pagination for CakePHP 1.3,它详细解释了分页器的工作原理。您最后的代码片段清楚地表明您不知道如何使用它。分页器本身将为您提取数据,您不会将结果集传递给分页器。只需查看文档,一切都在那里。

取自文件的例子:

public function list_recipes() {
    $this->paginate = array(
        'conditions' => array('Recipe.title LIKE' => 'a%'),
        'limit' => 10
    );
    $data = $this->paginate('Recipe');
    $this->set(compact('data'));
);