I try to get access via PHP to Joomla 4.3 articles using a standalone script.
In the following code I get a error in this line
$mvcFactory = \Joomla\CMS\Factory::getApplication()->bootComponent('com_content')->getMVCFactory();
I didn't get an error in the PHP log, just an 500 error from the Joomla framework: Sorry, there was a problem we could not recover from. The server returned a "500 - Whoops, looks like something went wrong."
My code:
use Joomla\CMS\Factory;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Table\Table;
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
define('JPATH_BASE', realpath(dirname(__FILE__).'/..'));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
$app = new Joomla\CMS\Application\SiteApplication();
\Joomla\CMS\Factory::$application = $app;
$app = Factory::getApplication();
$mvcFactory = $app->bootComponent('com_content')->getMVCFactory();
$articleModel = $mvcFactory->createModel('Article', 'Administrator', ['ignore_request' => true]);
$table = $articleModel->getTable();
Does anyone have an idea?
Thanks Robin
My goal is to access articles in Joomla 4 programmatically using PHP. And I want to know why this code is not working:
$mvcFactory = $app->bootComponent('com_content')->getMVCFactory();
$articleModel = $mvcFactory->createModel('Article', 'Administrator', ['ignore_request' => true]);
$table = $articleModel->getTable();
Tested on Joomla 5