Created
October 29, 2014 09:48
-
-
Save phproberto/42e2cdfda6f5002b839c to your computer and use it in GitHub Desktop.
Sample Joomla logout & redirect view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<metadata> | |
<layout title="COM_MYCOMPONENT_TITLE_VIEW_LOGOUT" option="View"> | |
<message> | |
<![CDATA[COM_MYCOMPONENT_TITLE_VIEW_LOGOUT_DESC]]> | |
</message> | |
</layout> | |
<fields name="params"> | |
<fieldset name="basic"> | |
<field | |
name="redirectUrl" | |
type="menuitem" | |
label="COM_MYCOMPONENT_LOGOUT_REDIRECT_URL" | |
description="COM_MYCOMPONENT_LOGOUT_REDIRECT_URL_DESC" | |
> | |
</field> | |
</fieldset> | |
</fields> | |
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Mycomponent.Frontend | |
* @subpackage View | |
* | |
* @copyright Copyright (C) 2014 Roberto Segura. All rights reserved. | |
* @license GNU General Public License version 2 or later; see LICENSE | |
*/ | |
defined('_JEXEC') or die; | |
/** | |
* Logout View. | |
* | |
* @package Mycomponent.Frontend | |
* @subpackage View | |
* @since 1.0 | |
*/ | |
class MycomponentViewLogout extends JViewLegacy | |
{ | |
/** | |
* Method to override in each controller | |
* | |
* @param boolean $cachable If true, the view output will be cached | |
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. | |
* | |
* @return string | |
*/ | |
public function display($cachable = false, $urlparams = array()) | |
{ | |
$app = JFactory::getApplication(); | |
$pageParams = $app->getParams(); | |
$itemId = $pageParams->get("redirectUrl"); | |
$redirectUrl = JUri::root(); | |
if ($itemId) | |
{ | |
$menuItem = $app->getMenu()->getItem($itemId); | |
$redirectUrl = JRoute::_($menuItem->link . '&Itemid=' . $menuItem->id, false); | |
} | |
$link = "index.php?option=com_users&task=user.logout&" . JSession::getFormToken() . "=1" | |
. "&return=" . base64_encode(htmlspecialchars_decode($redirectUrl)); | |
$app = JFactory::getApplication(); | |
$app->enqueueMessage(JText::_('COM_MYCOMPONENT_USER_DISCONNECTED'), 'message'); | |
$app->redirect(JRoute::_($link, false)); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment