Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1635

Migrating and Upgrading to Joomla! 5.x • create Joomla instance for web page

$
0
0
I am trying to bring up to the latest usage convention an old Joomla 3 module. It is working, and

$user = Factory::getUser();

works fine. I note, though, that this is deprecated to be replaced with

$user = Factory::getApplication()->getIdentity();

and my problem is that this does not work (I just get an on-screen message that 'something went wrong'). Can anyone suggest what I am doing wrong in my instantiation sequence (below, copied - I believe - from web guidance on how to construct such a page)?


use Joomla\CMS\Factory;

define('_JEXEC', 1);

// get root folder
if (!defined('DS')) define( 'DS', DIRECTORY_SEPARATOR );
$rootFolder = explode(DS,dirname(__FILE__));

// current level in directory structure
$currentfolderlevel = 2;
array_splice($rootFolder,-$currentfolderlevel);
$base_folder = implode(DS,$rootFolder);

if (file_exists($base_folder . '/defines.php')) {
include_once $base_folder . '/defines.php';
}

if (!defined('_JDEFINES')) {
define('JPATH_BASE', $base_folder);
require_once JPATH_BASE . '/includes/defines.php';
}

// Check for presence of vendor dependencies not included in the git repository
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_ROOT . '/media/vendor')) {
echo file_get_contents(JPATH_ROOT . '/templates/system/build_incomplete.html');
exit;
}

if (file_exists(JPATH_BASE . '/includes/framework.php')) {

require_once JPATH_BASE . '/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;

Statistics: Posted by wetken — Wed Dec 18, 2024 11:42 am



Viewing all articles
Browse latest Browse all 1635

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>