从外部 php 文件访问 Joomla 3.9 中的文章,空白页?

Access articles in Joomla 3.9 from external php file, blank page?

我尝试通过 ID(比如 id 179)访问文章,但是在我的 Joomla 3.9.3 站点中,它显示一个空白页面并且没有任何反应。 这是我的代码(名称 get.php,它与 configuration.phpindex.phprobots.txt ... 在同一个根文件夹中)

<?php
    error_reporting(E_ALL);
    ini_set('display_startup_errors',1);
    ini_set('display_errors',1);
    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' );
    $app = JFactory::getApplication('');
    var_dump($app);
    $app->initialise();
    $db = JFactory::getDBO();// Joomla database object
    $sql = "SELECT fulltext FROM #_content WHERE id = 179";
    $db->setQuery($sql);
    $fullArticle = $db->loadResult();
    if(!strlen(trim($fullArticle))) $fullArticle = "Article is empty ";
    echo $fullArticle;
  ?>

当我 var_dump() 时甚至没有任何显示;

我做错了什么还是 Joomla 3.9.3 改变了我们的访问方式?

您可以尝试以下代码 -

<?php
error_reporting(E_ALL);
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';

$app = JFactory::getApplication('site');
// var_dump($app);
// $app->initialise();
$db = JFactory::getDBO();// Joomla database object
$sql = "SELECT `fulltext` FROM #__content WHERE id = 179";
$db->setQuery($sql);
$fullArticle = $db->loadResult();
if(!strlen(trim($fullArticle))) $fullArticle = "Article is empty ";
echo $fullArticle;