Skip to content

Instantly share code, notes, and snippets.

@phproberto
Created October 29, 2014 09:48
Show Gist options
  • Save phproberto/42e2cdfda6f5002b839c to your computer and use it in GitHub Desktop.
Save phproberto/42e2cdfda6f5002b839c to your computer and use it in GitHub Desktop.
Sample Joomla logout & redirect view
<?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>
<?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