How to paginate to see the data when I chose a certain condition?

advertisements

in the index.ctp, i can get view all the details of data for my customer table. I wan to have a function which let user to select view by company, when user select the company, i use javascript to get know the company id, but i got no idea how to sort the data view by the company id..

i wanted to just list out the data in the index.ctp when the user selected the company for view, all the data will have their own company, which just few company are provided. any idea to create this action?? by refreshing page and i get view the new list of data in index.ctp. thanks.

i am new to cakephp.


If what you really want is to filter (not sort) your data, you can do it with the paginate method/vars of the controller too:

   $this->Model->recursive = 0;
   $data = $this->paginate('Model', array('OR' => array(array('Model.type' => 1), array('Model.subtype LIKE' => '%SOMETHING%'))));
   $this->set('data', $data);

This would create a query like this:

   WHERE ((`Model`.`type` = 1) OR (`Model`.`subtype` LIKE '%SOMETHING%')

You can also pass conditions, sorting and all that straight to paginate() from the controller like so:

   $this->paginate['conditions'] = array('Recipe.title LIKE' => 'a%');
   $this->paginate['limit'] = 10;

Pagination, Controller Setup