我正在尝试为 Android 应用程序制作一个登录系统,该系统可与我的 2.5 Joomla 网站一起使用。我试图通过制作一个 Joomla 插件来做到这一点,Android 应用程序将发布数据发送到 php 文件,然后该文件对用户进行身份验证,以查看登录凭据是否正确。我整个下午都在努力让它工作,但似乎我所有导入 JFactory 的尝试都失败了。
我有下面的代码,在第一次提到 JFactory 时就会出现错误。我尝试导入它也不起作用。
<?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 的其他问题,但没有一个对我有用:
- 在 /var/www/joomla2.5/database.php 中找不到 JFactory、JDatabase 类 https://stackoverflow.com/questions/17939546/jfactory-jdatabase-class-not-found-in-var-www-joomla2-5-database-php
- 未找到“JFactory”类 https://stackoverflow.com/questions/8320773/class-jfactory-not-found
- 在外部 php 文件 Joomla 中包含 Jfactory 类 https://stackoverflow.com/questions/9459430/include-jfactory-class-in-an-external-php-file-joomla
所以我的简化问题是如何导入 JFactory 或至少在这种情况下解决它?任何感觉比我聪明的人都会很乐意回答这个问题:)
一般信息:
- 运行 php 5.1.13
- Joomla 2.5
- 在 wamp 服务器(本地主机)上测试
我建议采用官方 Joomla 方式并引导应用程序。我所做的工作非常好,并且是推荐的 Joomla 方式(我没有测试下面的代码,但它应该为您提供一个起点,因为它是从我的代码中的多个源复制粘贴的)。
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 https://github.com/joomla/joomla-platform-examples/tree/master/web.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)