idrezzz
idrezzz

Reputation: 94

pagination + search in cakephp

please help me how to make pagination in search result , i found some questions here but i still cannot understand .

this is what i want to do ,

user fill the input search then system show the result in pagination

if user click on pagination link so the system move to the target pagination without loose any information about search input .

i found information that the search criteria saved in session but i dont know how to make it .

i spent two days to make it but still get no result .

Upvotes: 0

Views: 3835

Answers (2)

mark
mark

Reputation: 21743

you should really look into the search plugin: https://github.com/dereuromark/search

it provides you this functionality without you having to reinvent the wheel. it also uses "best practice" approaches like PRG and easily extendable search configuration for LIKE etc.

Upvotes: 0

thecodeparadox
thecodeparadox

Reputation: 87073

$search_keyword =   $value_you_get_from_search_field || '';  
$this->paginate = array(
    ....
    'conditions' => array(
         'YOURMODEL.field LIKE' => '%' . $search_keyword . '%', // this condition will check for search value to corresponding field you want
         .....
     )
);

$search_results = $this->paginate(); // search result will contain query for your search with pagination

To hold the value for the search field you have to set the field value to view like following:

$this->set(compact('search_results', 'search_keyword'));

And you have to design you search field like following:

$this->Form->input('fieldname', array('type' => ...., 'value' => $search_keyword, ....));

NOTICE In the input field I set the value property as $search_keyword, which has been sent from controller. Initially it is '';

Upvotes: 2

Related Questions