Welcome Guest, Not a member yet? Register   Sign In
uri of previous page
#1

[eluser]dimis[/eluser]
I have a page for products of some producers and a add to cart function for these
Code:
glasses/productsupdatecart/$id
At ths function I want to redirect at the previous page-the page of producer.How can I find the uri for the page of producer at "addtocart" function (or how can I implement it)?
Dimis
#2

[eluser]GSV Sleeper Service[/eluser]
I'm using this method.
Code:
//open the form
form_open('/cart/index'.$this->uri->uri_string());

then in my Cart controller, index method I have this
Code:
// determine return path
$uri = $this->uri->uri_string();
if($this->uri->total_segments() > 1){
    $exploded = explode("/",substr($uri,1));
    // first segment will be cart, we don't need that
    $first = array_shift($exploded);
    // second segment will be index, throw that in the bin too
    $second = array_shift($exploded);
    $return_to = implode("/",$exploded);
}
//do stuff
// ...
redirect("/".$return_to);

so, effectively when I post data to my Cart controller I'm posting to /cart/index/uri/of/page/i/want/to/return/to/
#3

[eluser]sophistry[/eluser]
one drawback of the form action technique is the redirect target appears in the address bar and can be manipulated easily.

if you don't mind using cookies, you could store the uri_string in a session. less code, redirect target can be encrypted.

Code:
// in one controller method
$this->load->library('session');
// save the referring page in cookie so we can
// redirect back to it in another method
$this->session->set_userdata('referrer', $this->uri->uri_string());

// in any other controller method
$this->load->library('session');
redirect($this->session->userdata('referrer'));
#4

[eluser]barbazul[/eluser]
flash data could also work

http://ellislab.com/codeigniter/user-gui...sions.html
#5

[eluser]drewbee[/eluser]
Agreed. Flash data is my prefered way of doing this, or even regular session data.
#6

[eluser]GSV Sleeper Service[/eluser]
why do I always have to complicate things?! I spent a good two minutes writing that code above. I should have just stuffed the referrer into the session.




Theme © iAndrew 2016 - Forum software by © MyBB