我最近将我的网站升级为Joomla 3.
我已经构建了一个检索Joomla用户信息的外部应用程序。
以下代码适用于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);
?>
网站升级后,上面的代码在Joomla 3中不起作用。
首先,我发现DS已在Joomla 3中折旧。 其次,我发现Joomla 3中的$ mainframe也被折旧了。
所以这里是更新的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;
?>
不幸的是,上面的代码规范不起作用,它给了我一个空白页面。
任何帮助将不胜感激。
答案 0 :(得分:3)
我自己使用Joomla 3.2进行了测试,效果很好。这是您需要的所有代码。
define( '_JEXEC', 1 );
define('JPATH_BASE', '../' );
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$app = JFactory::getApplication('site');
$user = JFactory::getUser();
print_r ($user);
希望这有帮助
答案 1 :(得分:0)
您定义&#39; JPATH_BASE&#39;你需要删除尾随/ - 或者删除文件位置前/。