Enkhbilguun Erdenetsogt, I'm glad you liked the idea. It has worked well for me in the past. Just a heads up on an issue you may run into:
Due to the way apache handles forward slashes in urls, you may run into a problem trying to access the "referrer" parameter in your request if it is built like this: /login/referrer/path/to/page If you change it to use a query string, it should work: /login?referrer=path/to/page -- Hector On Thu, Aug 20, 2009 at 8:41 AM, Enkhbilguun Erdenetsogt < [email protected]> wrote: > Thank you Hector Virgen, Daniel Latter and kamil for your kind advise. > > I think setting a session variable to all the last visited pages may not be > a good solution. Also $this->_redirect($this->_request->getRequestUri()) > redirects to the current page. > > In my project, Hector's solution may work well. I will add extra variable > with $this->_request->getRequestUri() as a value to my link like: <a > href="<?php echo $this->baseUrl(); > ?>/login/referrer/$this->_request->getRequestUri()">Login</a> (in this case, > login is a action of a auth or user controller) > > Question is resolved now. > > Thank you Hector Virgen! ;-) > > > > Hector Virgen wrote: > >> I've used a query parameter to accomplish this. The link to my login page >> looks like this: >> >> <a href="/login?to=/some/other/page">Login</a> >> >> When the login page is visited, the auth controller checks for the "to" >> parameter and saves it in a session namespace that automatically expires in >> 5 minutes. When the user successfully logs in, it redirects to the value >> stored in the session or to a default home page if its not found. >> >> This allowed me to create a view helper that creates the login URL with >> the "to" parameter automatically set up. I also was able to create an action >> controller helper that does a redirect to the login page in case an >> unauthenticated user attempts to access a page that requires authentication. >> >> The same can be done with the logout link. >> >> -- >> Hector >> >> >> On Thu, Aug 20, 2009 at 4:09 AM, kamil <[email protected] <mailto: >> [email protected]>> wrote: >> >> Enkhbilguun Erdenetsogt pisze: >> >> Thank you for you email, Daniel Latter. >> >> As your advise, I created hidden form element that stores the >> page path, and it is working if the login is in the page the >> user was on. >> >> $returnUrl = new Zend_Form_Element_Hidden('returnUrl'); >> >> >> $returnUrl->setValue(Zend_Controller_Front::getInstance()->getRequest()->getRequestUri()); >> >> >> However, if a user is forwarded to the login page, above >> method won't work as I'm expecting. I don't know much about >> HTTP_Referrer, but I guess I would be the same as hidden form >> method. >> In that case, how can I store the page path? >> >> Please advise me. >> >> Thank you very much for your support. >> >> >> Daniel Latter wrote: >> >> Hi, >> >> You will need to capture and store the page path the user >> was on. Then you can use the redirector, see here: >> >> >> http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.redirector >> >> >> Dan >> >> 2009/8/20 Enkhbilguun Erdenetsogt <[email protected] >> <mailto:[email protected]> >> <mailto:[email protected] >> <mailto:[email protected]>>> >> >> Hello, >> >> I'm building a user login/logout functionality in my ZF >> project. I >> just want to forward a user, just logged in or out, to >> the page >> before the user logged in or out. Could you tell me >> which commands >> I should use? >> >> >> Thank you very much friends. >> >> >> >> >> Just redirect user to >> $this->_redirect($this->_request->getRequestUri()); >> it works :) >> But in my projects i am forwarding user to login page not >> redirecting , so the adress in browser does not change >> >> >> >
