Pages

Showing posts with label pagination. Show all posts
Showing posts with label pagination. Show all posts

Sunday, August 18, 2013

cakephp-Ascending Order in Pagination

Recently I faced an issue while implementing an "Order By" command in cakephp pagination it was not taking the regular cakephp syntax

So I performed the same as follows

$this->Paginate=array('limit'=>10,'order'=>array('Model.field1'=>'asc'));

remember I used regular order i.e.

$this->Paginate=array('limit'=>10,'order'=>array('Model.field1 ASC'));

but this did not work

Sunday, June 9, 2013

Cakephp-Sort by custom made field in MYSQL not working in pagination

Recently in one of my cakephp projects.I came across a issue in pagination and sorting of data on basis of a custom made field..

Case:
I had a MYSQL field "video_length" in STRING which should have been in TIME(DB was not created by me)...

My requirement was sort on basis of this field so in my find function of Model I used

"TIME_TO_SEC(UserVideo.video_length)" AS vid_len and sorted by the same

It was working fine in normal scenario but was not showing sorted results under pagination may be because it was not permanent column of table

Solution:

I did some tricky thing here..I needed the column in format TIME_TO_SEC so in my fields property in my find function I customized fields and added concerned field in name of old field sth like

$this->UserVideo->find('all',array('fields'=>array("TIME_TO_SEC(UserVideo.video_length)" AS video_length)))

See words marked in bold

And finally all was coming well under pagination as well