Development

Load joomla 4 framework in external PHP page

Load joomla 4 framework in external PHP page

A short PHP script that loads the Joomla 4 framework in an external PHP file, so you can use Joomla's database, users and session outside the CMS.

Below you can find a script that loads the joomla 4 (only 4) framework on an external PHP page

If you have to make a query that uses both 'where' and 'and', for instance you have to make a selection that has 2 variables, you can do this in the following manner:

// load J4 framework in external page // ************************************************************************** //No Direct Access define('_JEXEC', 1); define('JPATH_BASE', __DIR__ . '/../../..'); require JPATH_BASE . '/includes/defines.php'; require JPATH_BASE . '/includes/framework.php';
// Boot the DI container. $container = \Joomla\CMS\Factory::getContainer();
// Alias the session service key to the web session service. $container->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
// Get the application. $app = $container->get(\Joomla\CMS\Application\SiteApplication::class);  
// j4 framework loaded // ************************************************************************** // define namespaces // ************************************************************************** use Joomla\CMS\Factory; use Joomla\CMS\Uri\Uri; use Joomla\Registry\Registry; use Joomla\CMS\Language\Text;

 

Happy coding!

Stuck on something else?

Doctor Joomla is a project of Cloudfaction, a Dutch agency building and maintaining Joomla sites since 1999. The articles are made with the help of AI, so tell us if something does not match your screen. Mail info@cloudfaction.nl if you want someone to look at yours.

Rather have someone look at it

Doctor Joomla is a Cloudfaction project.

A Dutch agency that has been building and running Joomla sites since 1999. If your site needs more than an article can fix, get in touch.