J4 Issue ?
avatar thanhnv37
thanhnv37
29 Aug 2018

Steps to reproduce the issue

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

Expected result

Open single form page properly

Actual result

Error 404: The requested page can't be found.

System information (as much as possible)

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.

Additional comments

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!

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar thanhnv37 thanhnv37 - open - 29 Aug 2018
avatar joomla-cms-bot joomla-cms-bot - change - 29 Aug 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 29 Aug 2018
avatar mbabker
mbabker - comment - 29 Aug 2018

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.

avatar joomdonation
joomdonation - comment - 29 Aug 2018

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.

avatar franz-wohlkoenig franz-wohlkoenig - change - 29 Aug 2018
Title
404 The requested page can't be found
[4.0] 404 The requested page can't be found
Status New Discussion
avatar joomla-cms-bot joomla-cms-bot - edited - 29 Aug 2018
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Aug 2018

Changed Title to show its about 4.0.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/21904.

avatar franz-wohlkoenig franz-wohlkoenig - change - 29 Aug 2018
Category Router / SEF
avatar thanhnv37
thanhnv37 - comment - 29 Aug 2018

@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.

router.php.txt

avatar thanhnv37
thanhnv37 - comment - 29 Aug 2018

@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;
avatar joomdonation
joomdonation - comment - 29 Aug 2018

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?

avatar thanhnv37
thanhnv37 - comment - 29 Aug 2018

No, it doesn't work :)

avatar ggppdk
ggppdk - comment - 29 Aug 2018

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

avatar brianteeman
brianteeman - comment - 29 Aug 2018

@thanhnv37 Off topic but you should update the faq on your web site as under the gpl licence you can not restrict resale

avatar thanhnv37
thanhnv37 - comment - 29 Aug 2018

@ggppdk yes sure, the $segments variable is passed by reference.
I know this basic programming knowledge :)

avatar thanhnv37
thanhnv37 - comment - 29 Aug 2018

@brianteeman
Sorry, I don't understand it clearly.
There are many websites are selling extensions of Joomla clubs.
And that is accepted?

avatar brianteeman
brianteeman - comment - 29 Aug 2018

image
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

avatar ggppdk
ggppdk - comment - 29 Aug 2018

@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

avatar brianteeman brianteeman - change - 30 Aug 2018
Labels Added: J4 Issue
avatar brianteeman brianteeman - labeled - 30 Aug 2018
avatar brianteeman
brianteeman - comment - 7 Jun 2019

This really should be closed

avatar joomla-cms-bot joomla-cms-bot - change - 7 Jun 2019
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2019-06-07 22:22:22
Closed_By joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 7 Jun 2019
avatar Quy Quy - change - 7 Jun 2019
Closed_By joomla-cms-bot Quy
avatar joomla-cms-bot
joomla-cms-bot - comment - 7 Jun 2019

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/21904

Add a Comment

Login with GitHub to post a comment