![]() |
Storing a request URL - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Storing a request URL (/showthread.php?tid=32473) |
Storing a request URL - El Forum - 07-24-2010 [eluser]JohnDoerther[/eluser] Hi Guys, First of all thanks a bunch for the great help so far - I am currently into my first steps on developing a website with CodeIgniter, and I absolutely love the framework. I have noticed that, in a lot of cases, when I submit a form on a view I would just like to go back to the original page where the user filled out the form. This goes for a lot of things on the website I am creating, for example, the website includes a shopping cart - every time the cart is updated (I am using the Cart class...) I would just like to send the user back to where he came from. Is there an easy way to do this? Can I tell a controller: "handle a user form, but when loading the view just go back to the original page". This also goes for example for clicking a link that adds a product to a cart, deleting an item from a cart , ... Thanks in advance Storing a request URL - El Forum - 07-24-2010 [eluser]Twisted1919[/eluser] The easiest way i can see here is to use the http referer . You need to use a MY_Controller in order to achieve this . so you will have something like : Code: class MY_Controller extends Controller{ Of course you can always store the last url into your session but is a bit more complex, for what you need, the above example should be enough . Storing a request URL - El Forum - 07-24-2010 [eluser]JohnDoerther[/eluser] Thanks for the quick response once again, I will try this out later and report back - thanks! Storing a request URL - El Forum - 07-24-2010 [eluser]WanWizard[/eluser] Argee, although the complex option is the safer option: if you keep it server side, you don't have a problem with brower plugins or proxies filtering the REFERER. One option is to extend the session library: Code: class MY_Session extend Session Storing a request URL - El Forum - 07-24-2010 [eluser]Twisted1919[/eluser] Wan, correct me if i am wrong , but the session is called before the controller action take place , doesn't this mean, that the current url will be always overwritten when making a new request, resulting in a "referer" of the current page always ? Meaning that if you do a $_POST to action/make_post then redirect[ redirect($this->session->userdata('referer')); ], will redirect to same action/make_post ? (of course i am talking about the method you explained above) Storing a request URL - El Forum - 07-24-2010 [eluser]WanWizard[/eluser] Ah, you're right. I use a modified Session library that only writes the session once, at the end. I sometimes get confused between my code and standard CI, sorry. You could do Code: class MY_Session extend Session Storing a request URL - El Forum - 07-24-2010 [eluser]Twisted1919[/eluser] As i told before, it's a more complex way of achieving this, that's why i didn't started the discussion with session usage ![]() Storing a request URL - El Forum - 07-24-2010 [eluser]haydenk[/eluser] Sounds like everyone is letting it get more complex than it has to be. :| The shopping cart is going to keep everything in the sessions and the way you describe it, you basically want to allow the user to "Continue Shopping" after adding product to their cart, so just figure out where you want to direct the customer (link wise) and put a link up there that says "Continue Shopping". |