I'm upgrading my extensions to compatible with Joomla 4 alpha4, and I find an issue with new router system of Joomla 4.
My form builder component has 2 pages are list of forms page and single form page.
If I create menu item for only list of forms page, and not create for single form page, then I click on item from list of forms to open a single form page, it gives me a 404 error page not found.
For example, the url of list of forms page is:
http://dev.joomlageek.com/j40alpha/geek-form-builder/
And the url of single form page is:
http://dev.joomlageek.com/j40alpha/geek-form-builder/form/2-customer-satisfaction-survey
Open single form page properly
Error 404: The requested page can't be found.
I found the code snippet that is a cause of this error. It's in the file
libraries/src/Router/Router.php (line 149 - 152)
if (strlen($uri->getPath()) > 0)
{
throw new RouteNotFoundException(Text::_('JERROR_PAGE_NOT_FOUND'));
}
If I comment this code snippet, everything will works properly.
Please improve this feature to backward compatible with Joomla 3 router.
It will help developer much when upgrading their extensions to compatible with Joomla 4.
Thanks in advanced!
Labels |
Added:
?
|
If I remember exactly, I got the same issue in the past while working to make my extension works with Joomla 4. The solution was at the end of parse method of component router, we need to empty $segments array.
if (version_compare(JVERSION, '4.0.0-dev', 'ge'))
{
$segments = [];
}
I'm not sure if it's the right way but it works for me.
Title |
|
||||||
Status | New | ⇒ | Discussion |
Changed Title to show its about 4.0.
Category | ⇒ | Router / SEF |
@mbabker thank you for your explanation.
I understand that code snippet is used to ignore invalid URL for better web SEO.
But the build and parse methods of my router class still work properly, and urls was generated correctly. Because if I remove mentioned code above, my component can still handle these urls correctly.
And the router class is working fine on Joomla 3.
I guess that other developer will face the same issue when upgrading their component.
I attached my router.php file below, could you please check and tell me what is the best way to upgrade it to work compatible with both Joomla 3 and Joomla 4.
@joomdonation
Thank you for your solution.
It was an exactly what I tried, but It seem does not work now.
I added the code below at the end of parse method for testing, but it did not help to resolve this issue.
if(JVersion::MAJOR_VERSION >= 4) {
$segments = array();
}
return $vars;
Not having a Joomla 4 installation available now for testing, but maybe you can try to remove the if, just add $segments = array(); to see whether it works?
No, it doesn't work :)
Besides emptying $segments
before return,
also please look at the function signature,
check that the $segments
is passed by reference
function nnnParseRoute(& $segments)
and retest to see if it works
@thanhnv37 Off topic but you should update the faq on your web site as under the gpl licence you can not restrict resale
@brianteeman
Sorry, I don't understand it clearly.
There are many websites are selling extensions of Joomla clubs.
And that is accepted?
This is against the gpl as it places a restriction on what i can do with the software - see freedoms 2 and 3 https://www.gnu.org/philosophy/free-sw.html
@ggppdk yes sure, the $segments variable is passed by reference.
I know this basic programming knowledge :)
ok i see,
i mentioned it
because i had exactly same problem, as you described
and this change solved the issue
and also because all 3rd party extensions for --J3-- i have now installed locally for testing do not pass the variable by reference, and they will need to be updated ?
it must be something else then
Labels |
Added:
J4 Issue
|
This really should be closed
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-06-07 22:22:22 |
Closed_By | ⇒ | joomla-cms-bot |
Closed_By | joomla-cms-bot | ⇒ | Quy |
Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/21904
Without seeing more of your router code, there is honestly no way to identify if there is a core bug or your component's router is missing some functionality. The lines you've pointed out throw that exception because after the parsing stages have been processed there should be no remaining unprocessed URI segments in the path. If I had to take a guess, the
/form/2-customer-satisfaction-survey
portion of the path isn't actually being processed when routing to your single form page and causing the exception.Note that removing this exception is actually a bad move as it would mean that partial URLs could be made to match a page and the rest of the URL wouldn't make a difference to processing the route (as is the case in the 3.x "legacy" router code, using your site as an example https://www.joomlageek.com/blog/88-geek-landing-page-3-7-0-ready-for-joomla-4 is the correct URL for your latest blog post and that exception should in theory block https://www.joomlageek.com/blog/88-geek-landing-page-3-7-0-ready-for-joomla-4-and-even-more-future-releases from giving a 200 response as is the case now if the com_content router doesn't find a match for that URL and process it accordingly.