一尘不染

从外部脚本访问Joomla 2.5以按ID获取文章

sql

我喜欢阅读ID的Joomla
2.5文章。由于我不在框架内,因此必须首先将其包括在内。我还发现了一些示例,该示例如何通过id获取文章,但是却失败了。这是我正在尝试的示例:

define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
echo JPATH_BASE .DS.'includes'.DS.'framework.php';
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
echo  $mainframe->getCfg('sitename');

$articleId = JRequest::getInt('Itemid');
$db =& JFactory::getDBO();

$sql = "SELECT fulltext FROM #__content WHERE id = 260"; //.intval($articleId);
$db->setQuery($sql);
$fullArticle = $db->loadResult();

商品ID 260可用,但它返回null。

当我跟踪它时,loadResult()中的$ cursor为每个null:

public function loadResult()
{
    // Initialise variables.
    $ret = null;

    // Execute the query and get the result set cursor.
    if (!($cursor = $this->execute()))
    {
        return null;
    }
     ...

有人可以帮忙吗?

谢谢安德烈


阅读 159

收藏
2021-03-17

共1个答案

一尘不染

您的脚本中有一些不需要的东西,我将其更改为Joomla 2.5编码标准:

define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
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 = 260');
$db->setQuery($query);

$fullArticle = $db->loadResult();

echo $fullArticle;

希望这可以帮助

2021-03-17