如何在paginate中组合多个查询

时间:2013-05-03 15:20:08

标签: cakephp pagination multiple-select

在我的应用程序中,我希望通过邮政编码集成距离搜索。

$result['zipcode'] = $this->Locations->find('all', array('conditions' => array('plz' => $param)));
if (count($city['Plz']) > 1)
    $result['city'] = $this->Locations->find('all', array('conditions' => array('ort' => $city['Stadt']['name'], 'plz !=' => $city['Plz']['zipcode'])));
    $this->Locations->virtualFields['distance'] = 'ACOS(SIN(RADIANS(Locations.lat)) * SIN(RADIANS('.$city["Stadt"]["lat"].')) + COS(RADIANS(Locations.lat)) * COS(RADIANS('.$city["Stadt"]["lat"].')) * COS(RADIANS(Locations.lng) - RADIANS('.$city["Stadt"]["lng"].')) ) * 6380';
    $result['near'] = $this->Locations->find('all', array(
        'conditions' => array(
            'plz !=' => $param,
            'ort !=' => $city['Stadt']['name'],
        ),
        'order' => 'distance ASC'
    ));

我希望按照邮政编码,城市(如果城市有很多邮政编码)和附近的顺序显示结果,所以我就是这样做的。 但现在我想通过蛋糕分页对这个结果进行分页。 是否有可能使这些查询得到一个,即

$this->Locations->find('all', array('conditions' => array(
    'order' => 'RESULTS BY ZIPCODE, RESULTS BY CITY, RESULTS BY MISSMATCH ORDERED BY DISTANCE'
)));

你会如何解决这个问题?

微米。

1 个答案:

答案 0 :(得分:0)

在CakePHP中,您可以通过关联数组指定多个要排序的字段;

$this->MyModel->find('all', array(
    'conditions' => array(/* .... */),
    'order' => array(
        'MyModel.field1' => 'asc',
        'MyModel.field2' => 'desc',
        'MyModel.field3' => 'asc',
    )
);
相关问题