sorting - CakePHP 2.4.4 Unable to sort/order by virtual field with paginate (Paginator) -


my virtual field property model, generated in beforefind(), called 'distance', works. however, can't sort it. have part of search form:

echo $this->form->input('sort', array(     'options' => hash::get($predefined, 'sort'), // list of options )); 

which adds sort url, , works normal fields, not virtual field distance. should have implemented differently? far i'm aware, virtual fields should work fine pagination.

edit: in case i've implemented pagination wrong...

i've set defaults:

public $paginate = array(     'limit' => 25,     'order' => array(        'properties.id' => 'asc'     ) ); 

after building $conditions:

$this->paginator->settings = $this->paginate; $data = $this->paginator->paginate('property', $conditions); $this->set('properties', $data); 

the above works fine changing order, directly editing /sort:fieldname/ in url, not virtual field 'distance'. tried adding, without success:

$this->paginate['order'] = array($value); //value value 'sort' named parameter 

this part of message:

my virtual field property model, generated in beforefind(),

seems issue.

the virtual field needs defined before call paginate() paginator knows build "sort" criteria.

the beforefind() call happens after pagination call, virtual field not yet defined. moving definition of virtual field right above the pagination call should fix this.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -