I am trying to come up with the best way (within the Zend Framework) to keep whatever page you request, and then if you are not logged in, it saves that url you requested, and once you login, it sends you back where you were. I kind of figured this is what controller plugins are for... I already have an Auth plugin that basically detects if you are authenticated and authorized to view whatever you're requesting, and if you aren't it boots you to the login screen. Seems like the perfect place to put it... but as far as design goes, I'm not sure that this is where it belongs. Should I write a second plugin?
Also, even if/when I do write the plugin, I'm sort of unsure how to go about it. The controller plugins thing has got me a little confused, so I'm just looking for advice.
Zend Framework - a "back to where you came from" p
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Right.. but say you're using a post-redirect-get pattern. How does the controller determine the logic in this situation?
Perhaps store page path info in the session?
Perhaps store page path info in the session?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
<?php
require_once 'Zend/Session/Namespace.php';
class Zodiac_Plugin_AuthRedirect extends Zend_Controller_Plugin_Abstract
{
public function __construct()
{
$this->_session = new Zend_Session_Namespace('authenticate');
}
public function preDispatch($request)
{
//perform the authentication here
if (!$this->_session->authenticated) {
}
}
public function postDispatch($request)
{
$controller = $request->getControllerName();
//if we have a url to redirect to, is authenticated and is still on the login controller
if ($this->_session->lastRequest && $this->_session->authenticated && $controller == 'login') {
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->setGotoUrl($this->_session->lastRequest);
}
//store the last url excluding those when on the login page
elseif ($controller != 'login' && !$this->_session->authenticated) {
$this->_session->lastRequest = $request->getRequestUri();
}
}
}
?>Thoughts?