从外部脚本访问 Joomla 2.5 以通过 id 获取文章 [英] Access Joomla 2.5 from external script to get article by id

查看:17
本文介绍了从外部脚本访问 Joomla 2.5 以通过 id 获取文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I like to read an article by id from Joomla 2.5. As I'm not inside the framework I've to include it first. I found also some samples how to get an article by id than but it ever fails ... This is the sample I'm trying:

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 ...

Article ID 260 is available but it ever return null ...

当我跟踪它时,loadResult() 中的 $cursor 是每一个空值:

When I trace it $cursor in loadResult() is every 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 编码标准:

There are a few things you don't need in your script and I have changed it to Joomla 2.5 coding standards:

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;

希望能帮到你

这篇关于从外部脚本访问 Joomla 2.5 以通过 id 获取文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆