在Joomla 3.4中,JFactory::getApplication('site');停止工作



我从以下代码中使用了以下代码:https://stackoverflow.com/a/2288181/4819200

<?php
//http://domain.com/script/script.php?username=username&passwd=password
define( '_JEXEC', 1 );
define('JPATH_BASE', '../' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once('../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' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');
$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'method', 'passwd');
//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
//now you are logged in
$mainframe->logout();
//now you are logged out

现在,问题

它在Joomla 2.3版本中工作,并且停止在3.4版本中使用。现在,它没有从行 $ MainFrame =&amp;jfactory :: getApplication('site');

您可以建议我为最新版本的代码。

注意:我不是Joomla Guy。但是,我在一些PHP框架上工作。

在Joomla 3中您可以使用此代码从Joomla外部获取用户对象

<?php
//http://domain.com/script/script.php?username=username&passwd=password
$dir = '/var/www/joomla'; // path to your joomla installation directory
define( '_JEXEC', 1 );
define( 'JPATH_BASE', $dir);
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' );
//Then you can call the classes this way
$mainframe = JFactory::getApplication('site');
/* Create the Application */
//$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');
$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'method', 'passwd');
//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
//now you are logged in
$mainframe->logout();
$code = NULL;
$plugin_param->params = new JRegistry($plugin_param->params);
$is_valid = $plugin->checkAnswer($code);

最新更新