Posted By

jiewmeng on 07/27/10


Tagged

zend-framework


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

osirisinternet


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


 / Published in: PHP
 

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
  1. // view helper
  2. class Application_View_Helper_LogoutLink extends Zend_View_Helper_Abstract {
  3. function logoutLink() {
  4. $returnUrl = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
  5. return '<a href="/auth/logout/?returnUrl=' . urlencode($returnUrl) . '">Logout</a>';
  6. }
  7. }
  8.  
  9. // Bootstrap.php
  10. // register your view helper
  11. function _initViewHelpers() {
  12. $this->bootstrap('view');
  13. $view = $this->getResource('view');
  14. $view->addHelperPath('Application\View\Helper', 'Application_View_Helper_');
  15. }
  16.  
  17. // in your view/layout scripts
  18. echo $this->logoutLink();
  19. // renders something like
  20. // <a href="/auth/logout/?returnUrl=%2Finspiration">Logout</a>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Roen on January 20, 2011

It's ideal for sites viewed by both 'guests' and 'users'. Matthew shows the 'extended' version

You need to login to post a comment.