我需要从 Joomla 本身之外的程序中获取当前登录到 Joomla 的用户的信息。我从 1.5 升级到 2.5,我之前拥有的不再工作了。
<?php
define( '_VALID_MOS', 1 );
include_once( 'globals.php' );
require_once( 'configuration.php' );
require_once( 'includes/joomla.php' );
$option="test";
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();
$my = $mainframe->getUser();
$joomla_name = $my->name;
$joomla_email = $my->email;
$joomla_password = $my->password;
经过一番研究,我想出了这个:
<?php
define( '_JEXEC', 1 );
define( 'JPATH_BASE', dirname(__FILE__) );
define( 'DS', '/' );
require_once ( JPATH_BASE .DS.'configuration.php' );
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.'factory.php' );
$my =& JFactory::getUser();
$joomla_name = $my->name;
$joomla_email = $my->email;
$joomla_password = $my->password;
$joomla_username = $my->username;
它不会产生任何错误,但似乎可以工作。但是,用户对象是空的。此脚本与 Joomla 安装位于同一目录中。可能是什么问题?谢谢!
资料来源:
http://www.cmsboke.com/accessing-joomla-objects-from-an-external-script/