tags:

views:

40

answers:

3

Newbie php question

I have a textbox where a user searches for something and a bunch of results are returned (search() method in the controller) when i click on a link, i want some more information to be displayed (searchMore() method in controller).

Questions

1) How can I go back to the the same search.ctp page instead of creating a new search_more.ctp ? Use elements or php includes ? Use redirects ? 2) How can I retain the user input data on the text box when I go back there from searchMore() ? Does cakephp provide any helpers for sessions and such ?

Thanks

+1  A: 

Your question looks like a pagination problem.The easiest solution would be,paginate your search results only two pages using the Paginator Helper,then you can easily switch them to each other.Another approach is Ajax solution which paginates like Twitter.

Update:(you'd better make your answer as a comment.)

Well,If I understand you correctly,you have same controler ,same search conditions,but you put them in diffrent actions while you need them use same view file.

For question 1),it can be done by using functin render

    $this->render('search');

in your more_search action.

For question 2),you can pass the user's input data as parameters between the two actions,or you can store them in session.

But it looks quite a bit odd.As far as I can see,a better solution is doing your work in one action since you have the same condition and the same output format.Then it will be a work about pagination.

SpawnCxy
A: 

This has nothing to do with pagination.

Mat
thanks but the issue im finding is that when i go back to search.ctp from searchMore(), my form input (i.e whatever the use put in the search box) is not being remembered anymore. how can i solve this in cakephp?
Mat
A: 

I'm often doing stuff like this - like the insert records mechanism in PhpMyAdmin (start again with 25 records).

In searchMore(), use $this->render('search'); That will send you back to the original view. Pass a variable like:

$this->set('searchMore',true); in your searchMore() method.

In the view, use a conditional (if($searchMore){...}), if required, to display alternate HTML in the view as required.

Leo