php - 从外部脚本访问 Joomla 2.5 以通过 id 获取文章

标签 php sql joomla article

我喜欢阅读 Joomla 2.5 中 id 的一篇文章。 由于我不在框架内,因此我必须首先将其包含在内。 我还发现了一些如何通过 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;
    }
     ...

有人可以帮忙吗?

谢谢 安德烈

最佳答案

脚本中有一些内容是不需要的,我已将其更改为 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;

希望这有帮助

关于php - 从外部脚本访问 Joomla 2.5 以通过 id 获取文章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15042262/

相关文章:

javascript - 如何在服务器上保存div内容(img)

sql - 使用MySQL计算中位数的简单方法

sql - 如何删除具有特定字符的行

sql - mysql选择以 future 记录的存在为条件

javascript - 根据用户ID隐藏div?

javascript - 动态构建包含 html 的 ajax 调用的数据字符串

php - 同时改变两个变量会产生不同的结果

php - Mailgun 发送邮件 laravel

php - 覆盖joomla类别 ListView

mysql - Joomla SQL 错误 0