簡體   English   中英

在外部php頁面中檢索Joomla 2.5數據

[英]Joomla 2.5 data retrieve in external php page

我在網站上使用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;

這段代碼非常適合從特定文章中獲取文章文本。 當然,它並不是那么有用,因為我想解決類別和多語言內容。

我將添加一切以更好的方式解決問題的方法。 任何進一步的想法肯定會有所幫助!

您需要初始化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環境。

尼布拉! 您的代碼與我的代碼非常相似:

<?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文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM