php – 从外部脚本访问Joomla 2.5以获取id的文章

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 从外部脚本访问Joomla 2.5以获取id的文章脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我喜欢阅读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的文章全部内容,希望文章能够帮你解决php – 从外部脚本访问Joomla 2.5以获取id的文章所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。