Return to Snippet

Revision: 29350
at July 27, 2010 21:02 by jiewmeng


Initial Code
// view helper
class Application_View_Helper_LogoutLink extends Zend_View_Helper_Abstract {
	function logoutLink() {
		$returnUrl = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
		return '<a href="/auth/logout/?returnUrl=' . urlencode($returnUrl) . '">Logout</a>';
	}
}

// Bootstrap.php
// register your view helper
function _initViewHelpers() {
	$this->bootstrap('view');
	$view = $this->getResource('view');
	$view->addHelperPath('Application\View\Helper', 'Application_View_Helper_');
}

// in your view/layout scripts
echo $this->logoutLink(); 
// renders something like 
// <a href="/auth/logout/?returnUrl=%2Finspiration">Logout</a>

Initial URL

                                

Initial Description
on 2nd thought, if a user logged out from a page only for logged in user, he will see a message stating he needs to login or similar, not ideal ... 

technical implementation: 

- use a view helper
- register the helper in bootstrap
- use view helper in view scripts

Initial Title
Zend Framework: After logout, redirect the user to the page he came from

Initial Tags

                                

Initial Language
PHP