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

General Questions/New to Joomla! 5.x • Can't get userId to pass to slim 4 code

$
0
0
Hello,

I have a website that's in Joomla 5 and runs just fine, but I have some custom php tools that will run outside of Joomla. These tools are built in Slim 4. Since the access controls are configured in Joomla I want to get the user object of someone who is logged in and pass the user ID of the logged in user to my Slim 4 code. I've dug around the forums and found this code that I've trying to build as a middleware in my Slim application:

Code:

define('_JEXEC', 1);define ('JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ]);require_once JPATH_BASE . '/includes/defines.php';require_once JPATH_BASE . '/includes/framework.php';// Boot the DI container$joomlaContainer = \Joomla\CMS\Factory::getContainer();$joomlaContainer->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$joomlaApp = $joomlaContainer->get (\Joomla\CMS\Application\SiteApplication::class);// Set the application as global app\Joomla\CMS\Factory::$application = $joomlaApp;//Get user info$userInfo = \Joomla\CMS\Factory::getApplication()->getSession()->get('user');
However on this line

Code:

$joomlaContainer = \Joomla\CMS\Factory::getContainer();
I get the following error:

Code:

Compile Error: Declaration of Joomla\DI\Container::has($resourceName) must be compatible with Psr\Container\ContainerInterface::has(string $id): bool
From what I'm seeing online, the solution is to update Joomla, but I'm already running 5.1.0. Any suggestions of how to tackle this would be appreciated

Statistics: Posted by Pallieguy — Tue Apr 16, 2024 7:15 pm



Viewing all articles
Browse latest Browse all 1690

Trending Articles





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