Wednesday, February 8, 2012

cakephp 2.0 pagination with search field

HI,
i'm trying to make an pagination search with cakephp 2.0
i want i pagination result with search field filled with the key

in the page i do somethings like this

echo $this->Form->create('News',array('class'=>'form-register'));
echo $this->Form->text('News.search');
echo $this->Form->submit('Ricerca');
echo $this->Paginator->counter(array( 'format' => __('Pagina {:page}
di {:pages}, vedi {:current} risultati di {:count} totali') ));


in controller
$this->News->recursive = 0;
$conditions = array();
if(!empty($this->data)) {
$search = $this->data['News']['search'];
} elseif($this->Session->check($this->name.'.search')) {
$search = $this->Session->read('News.search');
}
echo ' ricerca '.$search;
if(isset($search)) {
$input = $search;
App::import('Sanitize');
$q = Sanitize::escape($input);
$conditions = array(" MATCH(titolo,testo) AGAINST('$q'
IN BOOLEAN MODE) ");
$this->Session->write('News.search', $q);
$this->set('ilfiltro', $search);
}
$this->set('ops', $this->paginate($conditions));

how to filled the search field?
how to reset the search?

please apologize my English

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: