I've upgraded a Joomla 3.10 website to 4.x. I use custom scripts on the website wich use the framework and that worked fine until after the upgrade.
I did some searching and since the framework got an update i updated the framework and changed the script to reflect the changes. I downloaded the new framework from GitHub and installed it with composer.
However, i'm just getting a blank page. The code for the script is:
<?php ini_set('display_errors', 1); error_reporting(E_ALL); define('_JEXEC', 1); define('JPATH_BASE', __DIR__); require_once '/home/dfk/domains/dfk.be/public_html/libraries/src/Factory.php'; require_once '/home/dfk/domains/dfk.be/public_html/libraries/src/User/User.php'; // Initialize the application $app = JFactory::getApplication('site'); $app->initialise(); use Joomla\CMS\Factory; use Joomla\CMS\User\User; // Initialize the application $app = Factory::getApplication('site'); $app->initialise(); $user = User::getInstance(); $userID = $user->id; $username = $user->username; echo "UserID:" . $userID; ?>
I get no output at all, not even the "UserID:" string. No errors, so very hard to troubleshoot.
I've googled and tried some suggestions and nothing worked. Also tried some ChatGPT suggestions ;), but that didn't help either.
Is there anyone who has any tips on what could be wrong? Thanks in advance.
With the following code that i found in article Acess Joomla framework from external php file i can retrieve the session data, but i do not know how to use user data with this. Can anyone help me out with this please. There is very little documentation on the current framework, and most is outdated.
<?php if (!defined('_JEXEC')) define('_JEXEC', 1); if (!defined('JPATH_BASE')) define('JPATH_BASE', '/home/dfk/domains/dfk.be/public_html/'); require_once '/home/dfk/domains/dfk.be/public_html/includes/defines.php'; require_once '/home/dfk/domains/dfk.be/public_html/includes/framework.php'; // Boot the DI container $container = \Joomla\CMS\Factory::getContainer(); /* * Alias the session service keys to the web session service as that is the primary session backend for this application * * In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects * is supported. This includes aliases for aliased class names, and the keys for aliased class names should be considered * deprecated to be removed when the class name alias is removed as well. */ $container->alias('session.web', 'session.web.site') ->alias('session', 'session.web.site') ->alias('JSession', 'session.web.site') ->alias(\Joomla\CMS\Session\Session::class, 'session.web.site') ->alias(\Joomla\Session\Session::class, 'session.web.site') ->alias(\Joomla\Session\SessionInterface::class, 'session.web.site'); // Instantiate the application. $app = $container->get(\Joomla\CMS\Application\SiteApplication::class); // Set the application as global app \Joomla\CMS\Factory::$application = $app; var_dump($app);