I recently upgraded my website to Joomla 3.
I have built an external application which retrieve Joomla User Information.
Below code worked perfectly for Joomla 2.5:
<?php
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', '../' );
//Including the defines.php and framework.php of Joomla 2.5 CMS
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries' .DS. 'joomla'. DS. 'user' .DS. 'authentication.php');
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
//Accessing the Users table in Joomla 2.5 CMS
$mainframe->route();
$user =& JFactory::getUser();
print($user);
?>
After the site upgrade, the above code does not work in Joomla 3.
First I found that DS has been depreciated in Joomla 3. Second I found that $mainframe has also been depreciated in Joomla 3.
So here is the updated codespec:
<?php
define( '_JEXEC', 1 );
if(!defined('DS'))
{
define('DS',DIRECTORY_SEPARATOR);
}
define('JPATH_BASE', '../' );
//Including the defines.php and framework.php of Joomla 2.5 CMS
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries' .DS. 'joomla'. DS. 'user' .DS. 'authentication.php');
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$app = JFactory::getApplication();
$app->initialise();
//Accessing the Users table in Joomla 2.5 CMS
$app->route();
$user = JFactory::getUser();
print_r($user);
exit;
?>
Unfortunately the above codespec does not work, it gives me a blank page.
Any help will be appreciated.
getUser()
gets the current user object. - Lodder