User tests: Successful: Unsuccessful:
When working on the console, then routing in Joomla doesn't work propperly. Especially the widely used Route::_()
code is crashing. This pr adds a function to the console class to get the router object and fills the HTTP_HOST
server variable with the live site parameter.
doExecute
function:$this->ioStyle->success(\JRoute::_('index.php?option=com_content&view=article&id=1&catid=8'));
php cli/joomla.php user:list
Error in the terminal Call to undefined method Joomla\CMS\Application\ConsoleApplication::getRouter()
You see a green OK text with the SEF route to the article.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
I have tested this item
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
Labels |
Added:
?
|
Sorry this isn't correct (in my opinion) - I accept some of this is somewhat more subjective than other PR's though. There's kinda two parts here so I'm going to address each separately
First of all the getRouter
method. Happy to add that to the application so we can use \Joomla\CMS\Router\Route::link
. However in terms of the default router even though there is no site router - I think it's wrong to load the site router explicitly as the default. I'd rather it errors out by default if it's called with the wrong data rather than be wrongly relied on.
In terms of the setting of the HTTP_HOST
I'm very sure that overloading server side variables is wrong - plus we still end up with potentially bad behaviour here when live_site
isn't set (I'm still yet to set that on any of my sites) - and we just end up with that being null and still getting junk URLs out on each of those instances. This needs a proper fix (I'm not 100% sure how) where I guess the application has the ability to inject the base domain into the Uri::getInstance
method which would override the HTTP_HOST. Possibly by taking advantage of the WebApplication's https://github.com/joomla-framework/application/blob/2.0-dev/src/AbstractWebApplication.php#L1001-L1004 variables and doing some sort of similar config in the console application so we have consistency over both applications. Open to ideas on the best way forward there - but the idea being we need consistency over both web and console and to treat them as equals rather than bodging around the console.
Status | Ready to Commit | ⇒ | Needs Review |
First of all the
getRouter
method. Happy to add that to the application so we can use\Joomla\CMS\Router\Route::link
. However in terms of the default router even though there is no site router - I think it's wrong to load the site router explicitly as the default. I'd rather it errors out by default if it's called with the wrong data rather than be wrongly relied on.
I changed the code, so when no name is set that that an exception is thrown. But I left the code in place when a cli router is requested that it uses the site router as this is the case when Route::_()
is called.
I'm very sure that overloading server side variables is wrong
There is no other way to get the web site url than from the live site in console applications. But I removed it and now every extension dev has to set it in the console command by itself. Anyway, for me it is important to have routing work in console applications.
I changed the code, so when no name is set that that an exception is thrown. But I left the code in place when a cli router is requested that it uses the site router as this is the case when Route::_() is called.
But the entire point of Route::_ has always been it's been application specific. That's why we introduced Router::link to start with in 3.7 so we could do cross-application routing.
Status | Needs Review | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-01-02 23:47:27 |
Closed_By | ⇒ | wilsonge |
Thanks!
I think for 4.1 (as technically it's a low impact b/c break) we might also want to consider putting getRouter
into the \Joomla\CMS\Application\CMSApplicationInterface
so typehints work nicer - but this is definitely all we can do for the 4.0-dev branch.
Definitely, the whole getRouter stuff needs some love. @bembelimen can you ping me when 4.0-dev is merged into 4.1? So I will do a followup pr.
should fix #34840 i guess... i'll test later