Hi, I've managed to get the solution for my need.
So, I thought I'd share here hopefully can help anyone with the same
problem.
Just put this inside your controller (no need to create *paginate* function)
---
$recursive = -1;
$order = '';
$limit = 20;
$fields = array('DISTINCT No', 'Name', 'Expiry', 'Batchcode', 'Type');
$this->paginate = array(
'limit' => $limit,
'fields' => $fields,
'conditions' => $conditions,
'recursive' => $recursive,
'order' => $order,
);
$list_member = $this->paginate('Member');
---
You'll need the *paginateCount* function:
---
function paginateCount($conditions = null, $recursive = 0) {
$recursive = -1;
$fields = array('DISTINCT No', 'Name', 'Expiry', 'Batchcode', 'Type');
$params = array(
'conditions' => $conditions,
'recursive' => $recursive,
'fields' => $fields,
);
$results = $this->Member->find('all', $params);
return count($results);
}
---
and override the pagination value with some hacks.
---
$ttl_page = round($this->paginateCount($conditions)/$limit);
$this->params['paging']['Member']['pageCount'] = $ttl_page;
if($ttl_page==$this->params['paging']['Member']['page']){
$this->params['paging']['Member']['nextPage'] = '';
}
---
I know, this may not be the best solution, but it works out for me. If
anyone have a better solution, please share. Thanks.
On Mon, Dec 14, 2009 at 12:45 AM, E T <[email protected]> wrote:
> Hi all,
>
> I'm trying to display a list of records in my view and limiting the records
> to 20. However, there are duplicate data in the model. So the view is not
> displaying properly. I've tried this method (
> http://www.littlehart.net/atthekeyboard/2008/03/04/custom-cakephp-12-pagination-queries/)
> but when I override the paginate method, I cannot use $paginator in my view
> (the one that says Showing page x of x).
>
> I used this method in my controller:
>
> function paginate($conditions, $fields, $order, $limit, $page = 1,
> $recursive = null) {
> $recursive = -1;
> $fields = array('DISTINCT ID', 'Name', 'Expiry', 'Type');
> $params = array(
> 'conditions' => $conditions,
> 'recursive' => $recursive,
> 'fields' => $fields,
> 'order' => $order,
> 'limit' => $limit,
> 'page' => $page
> );
> return $this->Member->find('all', $params);
> }
>
> and call it using: $list = $this->paginate($conditions, '', '', $limit, 2);
>
> This will give me the correct data, but nothing in $paginator->counter().
>
> Any help is appreciated. Thanks.
>
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en