简体   繁体   中英

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

I try to access to article by ID (let say id 179), but in my Joomla 3.9.3 site, it show a blank page and nothing happen. Here is my code (name get.php , it's on same root folder with configuration.php , index.php , robots.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;
  ?>

Even nothing show when I var_dump() ;

What did i do wrong or Joomla 3.9.3 change the way we access?

You can try below code -

<?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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM