0

我在网站上使用 Joomla 2.5,但主页是一个外部 php 页面,我需要从特定的 joomla 文章和菜单项中获取数据。

  1. 调用模块或连接到数据库以检索我需要的最佳方法是什么?
  2. 如何调用 Joomla 类、函数等来获得我的结果?

我已经尝试过的:

此帖子中的“模块”解决方案(外部页面中的 Joomla 菜单)显示有关会话已启动的错误。

数据检索的一些代码:

define('_JEXEC', 1);
define('JPATH_BASE', dirname(__FILE__).'/../../Joomla_2.5.9' );   // should point to joomla root
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('introtext')
 ->from('#__content')
 ->where('id = 1');
$db->setQuery($query);

$fullArticle = $db->loadResult();

echo $fullArticle;

这段代码非常适合从特定文章中获取文章文本。当然,它不是那么实用,因为我想处理类别和多语言内容。

我将添加任何结果以更好地解决问题。任何进一步的想法肯定会有所帮助!

4

2 回答 2

2

您需要初始化 Joomla 应用程序:

$joomlaPath = dirname(__FILE__).'/../../Joomla_2.5.9';
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);

if (file_exists($joomlaPath . '/defines.php')) {
    include_once $joomlaPath . '/defines.php';
}

if (!defined('_JDEFINES')) {
    define('JPATH_BASE', $joomlaPath);
    require_once JPATH_BASE.'/includes/defines.php';
}

require_once JPATH_BASE.'/includes/framework.php';

// Instantiate the application.
$app = JFactory::getApplication('site');

// Initialise the application.
$app->initialise();

首先,您可以访问已配置的 Joomla 环境。

于 2013-04-05T13:25:14.790 回答
1

尼布拉!你的代码和我的很相似:

<?php
define( '_JEXEC', 1 );
define( 'JPATH_BASE', '/home/user7633/public_html/cms' );
define( 'DS', '/' );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
JFactory::getApplication('site')->initialise();
$user = JFactory::getUser();
echo $user->username;
?>

通过这种方式完成的代码不起作用

我在 PHP 5.4.36 上使用 Joomal 3.4.1,代码只是偶尔工作。有时用户名是空的,有时是例外。我已登录!

我从“外部 URL”菜单项调用 PHP 文件。

于 2015-05-15T10:33:54.110 回答