As soon as I try to load the Endpoint /api/index.php/v1/users, the repsonse is "Unable to load router: api".
JRouterApi should be alias for ApiRouter, like SiteRouter and AdministratorRouter.
$container->alias('AdministratorRouter', AdministratorRouter::class)
->alias('JRouterAdministrator', AdministratorRouter::class)
$container->alias('SiteRouter', SiteRouter::class)
->alias('JRouterSite', SiteRouter::class)
JRouterApi is no alias for ApiRouter.
$container->alias('ApiRouter', ApiRouter::class)
->share(
ApiRouter::class,
function (Container $container) {
return new ApiRouter($container->get(ApiApplication::class));
},
true
);
So the Joomla\CMS\Router\Router class will fail at:
$classname = 'JRouter' . ucfirst($client);
if (!class_exists($classname)) {
throw new \RuntimeException(Text::sprintf('JLIB_APPLICATION_ERROR_ROUTER_LOAD', $client), 500);
}
Joomla 4.4.8, PHP 8.1.29, Apache Server
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-09-30 10:12:54 |
Closed_By | ⇒ | Hackwar |
I know, but since it is in the core file "Joomla\CMS\Router\Router.php" (line 112 to 116 J! Version 4.4.8) it is core bug, isn't it?
There is a check if 'JRouter' . ucfirst($client) is a existing class (in this case "api"), and when it doesn't exits the programm will exit with JLIB_APPLICATION_ERROR_ROUTER_LOAD. So the core the core expects JRouteApi by itself.
Yes, but that method itself is deprecated and it is not the right method to retrieve every router. We wont change this. Please use the correct method as described above.
Thank you for reporting this, unfortunately however, JRouterAPI should not be an alias for ApiRouter, since all J-prefixes are only b/c aliases for Joomla 3, but the API has only been introduced in 4.0. You should not get the router with
Router::getInstance()
, but with$router = $this->getContainer()->get(ApiRouter::class);
. This is not a Joomla bug.