|
|||
|
Hello all,
First of all, I'm just getting started with the Zend Framework. I do like it a lot. I've run into a conundrum concerning logging in and referers. I'm trying to figure out the best way to explain it. I've got three controllers: Index, Auth, Update. Right now, if you try to go to any Update action without being logged in (via Zend_Auth), preDispatch() sending you to auth/login. That bit works fine. The problem is, I can't figure out a clean way of remembering whether you came to auth/login from update/add, update/edit, or update/delete. $_SERVER['HTTP_REFERER'] is only being set as the Index controller, not the update/{action} I'm going for. I hope that makes sense. Does anyone know of anything inside ZF that I can use to keep track of the referring action? Or know of a better way of doing this? Thanks, -mike Last edited by july4th : 02-22-2008 at 02:07 AM. |
|
|||
|
HTTP_REFERER is not working since you are sending users to the login form, which i'm guessing is located at /index, as opposed to embedded in all pages such as jhorra suggests.
This should work fine in your case: if (is_null($this->auth) || !$this->auth->hasIdentity()) { $session = new Zend_Session_Namespace('<insert a suitable namespace>'); $session->destination = $_SERVER['REQUEST_URI']; $this->_redirect('<insert login page>'); // since you are using a plugin this call will have to be modified. But you've already grasped that part. } Now when you've authenticated the user simply redirect them to $session->destination. Hope this helps. |
|
|||
|
Leif:
The login is a separate controller but I do that same check for auth->hasIdentity(). The problem I was running into is the action I was selecting in the Update controller was never being set as the HTTP_REFERER, probably because I never reached that action as the script never got past preDispatch(). I'll give the sessions a try but I was hoping there'd be something built into the framework to help. -Either that, or forgo the preDispatch() and check for auth->hasIdentity() in every action. Hmm.- Edit: Nope, didn't work. HTTP_REFERER is still being set as the index. Thanks for your reply. ![]() Last edited by july4th : 02-22-2008 at 11:55 AM. |
|
|||
|
Quote:
Worked like a charm. Thanks Leif. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|