Yeah,
I do realize having session is easier, but I'm practicing not to use
sessions so much. I did manage to use query in URL using get instead
of post (well, apparently if i use post, i will have to use sessions
later on, since there will be no more data to be passed on after going
to different pages). Here's what I have in my controller and view:
Partial APP/controllers/parts_controller.php:
function index($keyword = null)
{
if (isset($this->params['url']['keyword']))
$keyword = $this->params['url']['keyword'];
if ($keyword) {
$conditions = array("or" => array("name" => "LIKE
%".$keyword."%",
"part_number" => "LIKE %".$keyword."%",
"part_nokia" => "LIKE %".$keyword."%"));
$this->set('parts', $this->paginate('Part',
$conditions));
} else {
$this->Part->recursive = 2;
$this->set('parts', $this->paginate());
}
}
Partial APP/views/parts/index.ctp:
<?php
if (isset($this->params['url']['keyword']))
$currentUrl = $this->params['url']['keyword'];
else if (isset($this->params['pass']))
$currentUrl = $this->params['pass'];
else
$currentUrl = array();
echo $paginator->options(array('url' => $currentUrl));
?>
Now, my problem is the URL looks APP/parts?keyword=<input query> when
searching for the first time, and when I click on the next page (since
I use $this->params['pass'] in the view) it looks APP/parts/index/
<keyword>/page:<page_number>. A little ugly workaround, I think.
What I'm trying to do next is I want to make the URL to look APP/parts/
index/keyword:<input query>/. Is this possible? Because I have another
controller where there is more than 1 input box, and the address
becomes APP/controllers?
keyword=<query>&anotherkeyword=<another_query>, and with the current
solution I have, it no longer works, since index() only accepts one
field. I think if the URL can look APP/controllers/index/
keyword:<query>/keyword2:<another_query>, it will look better, and
will be easier to manage in my controller.
I would be very grateful for your help.
Thank you.
Reza Muhammad
On Jun 12, 2008, at 6:16 PM, Dardo Sordi Bogado wrote:
>
> Yes, put the parameters for the query in the URL (better) or in the
> Session (easier, bad) and paginate using that.
>
> On Thu, Jun 12, 2008 at 1:37 AM, Reza Muhammad
> <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> I'm having a problem with pagination after I searched for a
>> particular
>> field. In my index, I have a Spare parts lists, and users can search
>> for a particular parts they are looking for. The thing is, if the
>> result returns more than 20 items (which I use pagination), I can't
>> go
>> to the second page, or the third page, because it will go the index
>> pagination (second page/third page of all spare parts lists)
>>
>> Here's what I have in my parts_controller:
>>
>> function index()
>> {
>> if (!empty($this->data)) {
>> $conditions = array("or" => array("name" =>
>> "LIKE %".$this-
>>> data['Part']['keyword']."%",
>> "part_number" => "LIKE %".$this->data['Part']
>> ['keyword']."%",
>> "part_nokia" => "LIKE %".$this->data['Part']
>> ['keyword']."%"));
>> $this->set('parts', $this->paginate('Part',
>> $conditions));
>>
>> } else {
>> $this->Part->recursive = 2;
>> $this->set('parts', $this->paginate());
>> }
>> }
>>
>> I think the problem is, in index, it will look for $_POST data, but,
>> when I want to go to the second page, it will not go to the first
>> "if"
>> statement, and instead it will look for pagination from "else"
>> statement.
>>
>> Is there any simpler way to do this? I'm not looking for Ajax
>> solutions or anything like that, as long as it works.
>>
>> Thank you so much.
>> reza
>>
>>>
>>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---