CodeIgniter Forums
Back to the search result - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Back to the search result (/showthread.php?tid=52391)



Back to the search result - El Forum - 06-08-2012

[eluser]Omaplie[/eluser]
Hi everyone !

My question is simple : how can I design a « back to the search result » button ?
I created a search result who display a list of link.
How to do when a user go to one link and want to go back to his search result ?

I saw that I can use JS :
Code:
'[removed]window.history.go(-1);'
but I would like to do it in CI.

Someone can help me ?
Thank you a lot !


Back to the search result - El Forum - 06-09-2012

[eluser]Omaplie[/eluser]
Nobody can help me ?


Back to the search result - El Forum - 06-09-2012

[eluser]nagata[/eluser]
put this into page load part (somewhere in controller code)
Code:
$this->load->library('session');
$this->load->helper('url');
$my_url=current_url();
$this->session->set_flashdata('previus_adress', $my_url);

and put this code into controller function that displays the one result item
Code:
<?php
$this->load->library('session');

$my_url=$this->session->flashdata('previus_adress');
echo '<a href="'..'">Go Back to results</a>'
?&gt;

tell me if anything is wrong, I havent tested this code yet, but in theory,
if your search info is passed as url (ex. http:/localhost/index.php/search/trololo)
this code will in first part:
using url helper get the current url, and using session library will put that url into flash data as 'previus_adress'
and in the other part it will retrive that flash data from session using the session library
and echo it onto page in form of normal link

for the question why i use flashdata instead of normal session data is because flash data will exist only for one load, so no need to clear anything if user decides not to return back to result list


Back to the search result - El Forum - 06-09-2012

[eluser]Samus[/eluser]
Or just

Code:
$this->agent->referrer()

http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html


Back to the search result - El Forum - 06-09-2012

[eluser]Omaplie[/eluser]
Thank you very much for you answer.
I'll try both.


Back to the search result - El Forum - 06-09-2012

[eluser]Omaplie[/eluser]
I tried what you said nagata but unfortunately it doesn't work, it redirects me to the page before the search.
When I search something I have a « Page1 », I have a result « Page2 » and I choose a result « Page3 ».
The link from the « Page3 » redirect me to the « Page1 » and not to the « Page2 ».
My URL from the « Page2 » is like that : « http://localhost/web3/CodeIgniter/scout2gether/totem/search_totem »
That's why it doesn't work.
But I never pass values get from a form to a url, I am sorry.
I am looking on the internet but can you give me some informations about this ?
Thank you for your help.

Samus, I don't really understand the documentation about
Code:
$this->agent->referrer()
Can you give me more explanations please.

Thank you very much you both.


Back to the search result - El Forum - 06-09-2012

[eluser]Omaplie[/eluser]
It fine, I save the value that the user enter in a data and when I go back to the search result
I make the request with the value in the userdata.

It works fine, thank you very much