JFactory导入失败 [英] JFactory failing to import
问题描述
我正在尝试为适用于我的2.5 Joomla网站的android应用程序创建一个登录系统.我试图通过制作一个Joomla插件来做到这一点,该插件将android应用程序将发布数据发送到php文件,然后该文件对用户进行身份验证,以查看登录信息是否正确.我一直在努力使整个下午工作,但似乎我所有导入JFactory的尝试都失败了.
I am trying to make a login system for an android application that works in with my 2.5 Joomla website. I am trying to do this by making a Joomla plugin which the android application sends post data to a php file which that then authenticates the user to see if the credentials are correct or not for the login. I have been trying to get this working all afternoon but it seems all my attempts of importing JFactory are failing.
我有以下代码,这些代码在第一次提到JFactory时就会出错.我尝试导入它也不起作用.
I have the below code which bugs out at the first mention of JFactory. My attempt of importing it is not working either.
<?php
//needed to be commented out otherwise the android application cannot send data to the file
//defined('_JEXEC') or die;
define('_JREQUEST_NO_CLEAN', 1);
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
require_once JPATH_BASE.'/includes/helper.php';
require_once JPATH_BASE.'/includes/toolbar.php';
require JPATH_BASE.'/library/joomla/factory.php';
$email = $_POST['email'];
$password = $_POST['password'];
file_put_contents("Log.txt", "got data: ".$email." and ".$password);
$credentials->email = $email;
$credentials->password = $password;
$responce;
//error occurs here
$db = JFactory::getDbo();
...
?>
我查看了有关导入JFactory的其他问题,但没有一个对我有用:
- JFactory,JDatabase类未在/var/www/joomla2.5/database.php
-找不到"JFactory"类
-在外部php文件Joomla中包含Jfactory类
I have looked at these other questions about importing JFactory but none of them are working for me:
- JFactory,JDatabase class not found in /var/www/joomla2.5/database.php
- Class 'JFactory' not found
- include Jfactory class in an external php file, Joomla
所以我的简化问题是在这种情况下如何导入JFactory或至少解决该问题?谁会比我聪明,谁愿意回答这个问题:)
So my simplified question is how do I import JFactory or at least work around it in this situation? Anyone feeling smarter than me who would be so kind to answer the question :)
常规信息:
- 运行php 5.1.13
- Joomla 2.5
- 在wamp服务器(本地主机)上测试
推荐答案
我建议采用Joomla官方方式并引导应用程序.我所做的工作很好,并且是推荐的Joomla方式(我没有测试下面的代码,但是它应该为您提供一个起点,因为它是我代码中多个来源的复制粘贴).
I suggest to go the official Joomla way and bootstrap an application. What I did works pretty well and is the recommended Joomla way (I haven't tested the code below but it should give you a starting point as it was a copy paste from multiple sources in my code).
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
define('JPATH_BASE', dirname(dirname(dirname(__FILE__))));
require_once JPATH_BASE.DS.'includes'.DS.'defines.php';
require JPATH_LIBRARIES.DS.'import.php';
require JPATH_LIBRARIES.DS.'cms.php';
JLoader::import('joomla.user.authentication');
JLoader::import('joomla.application.component.helper');
class MyJoomlaServer extends JApplicationWeb {
public function doExecute() {
$config = JFactory::getConfig();
$email = $_POST['email'];
$password = $_POST['password'];
$user = ...;//get the user with the email
file_put_contents("Log.txt", "got data: ".$email." and ".$password);
$authenticate = JAuthentication::getInstance();
$response = $authenticate->authenticate(array('username' => $user->username, 'password' => $password));
return $response->status === JAuthentication::STATUS_SUCCESS;
}
public function isAdmin() {
return false;
}
}
$app = JApplicationWeb::getInstance('MyJoomlaServer');
JFactory::$application = $app;
$app->execute();
对我来说行之有效的事情.可以在此处找到更多平台示例 https://github.com/joomla/joomla-platform-examples/tree/master/web .
Something along the lines works for me. More platform examples can be found here https://github.com/joomla/joomla-platform-examples/tree/master/web.
这篇关于JFactory导入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!