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


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.