In Joomla 4, when I use "RouteHelper::getArticleRoute", I get the next error: "Attempted to load class RouteHelper from namespace Joomla\Component\Content\Site\Helper.

I want to use from a script where I load Joomla like this:

define('_JEXEC', 1);

if (file_exists(dirname(__DIR__) . '/defines.php')) {
    include_once dirname(__DIR__) . '/defines.php';

if (!defined('_JDEFINES')) {
    define('JPATH_BASE', dirname(__DIR__));
    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');

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);

How can I use "RouteHelper::getArticleRoute" there?

1 Answer 1


You need to register extension namespaces to use extension classes. This can be done with JNamespacePsr4Map::load():

JLoader::register('JNamespacePsr4Map', JPATH_LIBRARIES . '/namespacemap.php');
(new JNamespacePsr4Map)->load();

Or you can call the same code through the application:

  • Thank you. Works! But one question... When I do "RouteHelper::getArticleRoute(117, 59, 'es-ES')", the response is "index.php?option=com_content&view=article&id=117&catid=59". Where is the language in the response? Have I to load or start anything else?
    – Jon
    May 16 at 10:17
  • And another one.... When I do "Route::_(RouteHelper::getArticleRoute(117, 59, 'es-ES'))", the response is "/?view=article&id=117&catid=59". No SEF URL. What's happen?
    – Jon
    May 16 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.