Sha*_*jad 4 php mysql pagination cakephp cakephp-1.3
我有一个相当修改的分页查询使用了许多连接等 - 但由于某种原因,paginator-> counter()永远不会匹配计数查询的结果.
您可以在http://dev.qreer.com/上看到它的运行情况- 通过在LHS导航上选择各种选项,查询输出在下面,并且分页器计数看起来非常随机.
知道我可以开始调试这个吗?
在Jobs Controller中:
$this->paginate = $this->Job->paginateParams($data);
$jobs = $this->paginate('Job');
$this->set(compact('jobs'));
Run Code Online (Sandbox Code Playgroud)
在模型中:
function paginateParams($data = null){
//lots of joins + conditions
return array('contain' => $contain, 'recursive' => 0,'joins' => $joins, 'conditions' => $conditions, 'group' => 'Job.id', 'order' => $order);
}
Run Code Online (Sandbox Code Playgroud)
示例连接(所有连接表和数据表的内部连接):
array(
'table' => 'education_backgrounds',
'alias' => 'EducationBackground',
'type' => 'INNER',
'conditions' => array('EducationBackgroundsJobs.education_background_id = EducationBackground.id'),
),
Run Code Online (Sandbox Code Playgroud)
样品条件:
'EducationBackground.name' => array('Aerospace Engineering');
Run Code Online (Sandbox Code Playgroud)
ple*_*ong 10
这是因为group by我找到了一个解决方法.我想把链接但我已经丢失了,所以我会发布代码:
public function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
$parameters = compact('conditions', 'recursive');
if (isset($extra['group'])) {
$parameters['fields'] = $extra['group'];
if (is_string($parameters['fields'])) {
// pagination with single GROUP BY field
if (substr($parameters['fields'], 0, 9) != 'DISTINCT ') {
$parameters['fields'] = 'DISTINCT ' . $parameters['fields'];
}
unset($extra['group']);
$count = $this->find('count', array_merge($parameters, $extra));
} else {
// resort to inefficient method for multiple GROUP BY fields
$count = $this->find('count', array_merge($parameters, $extra));
$count = $this->getAffectedRows();
}
} else {
// regular pagination
$count = $this->find('count', array_merge($parameters, $extra));
}
return $count;
}
Run Code Online (Sandbox Code Playgroud)
我在app_model中添加了它,它对我来说很好:)
希望这可以帮助
编辑:我发现链接=)
http://wiltonsoftware.com/posts/view/custom-group-by-pagination-and-a-calculated-field