Like you say this has been discussed quite a bit before.
The way I was advised to do this (which works really well) is to
"POST" (or GET) the search to a proxy-action that creates a nice url
that paginator will play nice with and redirects you to our results.
Example:
function lookup()
{
if ( !empty($this->params['url']['q']) )
{
$param = $this->params['url']['q'];
$this->redirect('lookupResults/'.$param);
return;
}else{
// do something else here
}
}
This function would look for a GET parameter called q and redirect you
to /controller/lookupResults/test or something similar. This will then
be able to play nice with paginator if you add this to your view:
$paginator->options(array('url' => $this->passedArgs));
your next button would go to: /controller/lookupResults/test/page:2
double07 wrote:
> Hi all,
>
> I know there's a lot of info around on this already but I haven't been
> able to solve this issue myself.
>
> I'm just setting up a simple search which will trawl through the
> titles and bodies of news items.
>
> I borrowed some code from the bakery here:
> http://bakery.cakephp.org/articles/view/paginating-with-fulltext-searches
>
> I made a few minor changes but it's more or less the same
>
> in my news controller:
> function admin_search() {
> $this->News->recursive = 1;
> $conditions = array();
>
> if (isset($this->params['url']['q'])) {
>
> $input = $this->params['url']['q'];
>
> App::import('Sanitize');
> $q = Sanitize::escape($input);
>
> $options['conditions'] =
> array("MATCH(News.title,News.body)
> AGAINST('$q' IN BOOLEAN MODE)");
>
> }
>
> $this->set(array('results' => $this->paginate('News',
> $options['conditions'])));
>
> }
>
> In the bakery article they just had:
> $this->set(array('results' => $this->paginate('News', $options)));
> But that wouldn't work for me?
>
> So according to the manual to pass the query string to the paginator I
> just put this line of code at the top of my view:
> <?php $paginator->options(array('url' => $this->passedArgs)); ?>
>
> So it works as in it returns the first page of results (via /admin/
> news/search?q=test) but when I hover over the next/back/page number/
> filter links it doesn't pass on the search query string it just looks
> like:
> /admin/news/search/page:2
>
> If I manually enter a query string it works perfectly i.e. /admin/news/
> search/page:2?q=test
>
> Any ideas why the querystring isn't being used by the paginator?
>
> TIA.
>
> -Brett.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---