加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:40:53 所属栏目:PHP教程 来源:网络整理
导读:我喜欢阅读Joomla 2.5中的id文章. 因为我不在框架内,所以我首先要包含它. 我还发现了一些样本如何通过id获取文章,但它失败了…… 这是我正在尝试的样本: define( '_JEXEC',1 );define( '_VALID_MOS',1 );define( 'JPATH_BASE',realpath(dirname(__FILE__)))
我喜欢阅读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;

希望这可以帮助

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读