Making a component's router: router.php.
In the function "parse(&$segments)" the segments have already been tampered with by joomla itself (while not after the build function which is not consistent).
E.g. "my-personal-sef-url" becomes "my:personal-sef-url"
Since it is up to the component router to build the segments in the first place (by the build function) and thus his responsibility to make segments, Joomla should leave the segments sent afterwards to the parser alone. I am of course talking only about the segments targeted for this component and not the segments before that. Joomla can do what it wants with that.
I know this probably has to do with slug or similar, but whatever the reason, this is forcing component developers to use that "concept" of routing. This concept should be up to the component developer.
But OK, if any developer doesn't agree with the above concept responsibilty, then one should be consistent and make it so that the segments returned by the build function are also changed accordingly after building them. Than at least for someone not knowing this concept, both functions in router.php are complying to each other.
FYI:
This "bug" is already here since a long time it seems and people have changed the dash back to a colon in their routing. (Isn't that a bit inefficient, and again inconsistent?).
Here is one example, but more can be found via google:
http://stackoverflow.com/questions/13471360/joomla-component-sef-links-on-and-jrequestgetvar-not-returning-variables-fro
Labels |
Added:
?
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-01-04 18:03:34 |
Closed_By | ⇒ | Hackwar |
Set to "closed" on behalf of @Hackwar by The JTracker Application at issues.joomla.org/joomla-cms/5579
First of, thanks for your insights.
So, it's agreed upon "up there" that it was inconsistent? It just remains for compatibility reasons? Fair enough.
Regarding class: That is strange, because I did make it in a class. I even looked a bit at com_content. If I find time I will look into it.
First thoughts already: I díd make it a standard object class; I saw no reason to implement the router interface com_content is using. Could that be the reason? If so, I gather that joomla is looking at the class to decide what to do with segments?
No, Joomla expects you to either provide a function based router or provide a class based router that implements the JComponentRouterInterface. If you did not implement that interface, Joomla will refuse to accept that router.
It was agreed that that colon-to-dash and dash-to-colon thing was a stupid idea about a quadrillion years ago, but since there was no one who wrote new routers, it was pulled along and since we are sticking to semantic versioning, we can't simply drop it, but have to wait for the next major release (in this case 4.0)
You don't need to provide the functions that are in the com_content router at the bottom. Those are again only for backwards compatibility. If you did provide them and did not implement the above mentioned interface, Joomla will not use your class based router and instead fall back to the function router and also behave accordingly.
I see. I did indeed make normal functions that used the methods of my own class, like com_content did. And I made my class static for further performance.
But, as I gather, just making the interface extension would be better and joomla would call the methods in there without further reference. Good to know.
Correct me if I am wrong or any more references welcome. I'm adding this to the Joomla Docs.
I added it here int he docs as important note at the top, in case anyone wants to add things:
https://docs.joomla.org/Supporting_SEF_URLs_in_your_component
this is all currently in flux and will change heavily for at least 3.5, maybe even already in 3.4, so documenting this now is a bit premature. See all my PRs prepended with "Routing" https://github.com/joomla/joomla-cms/pulls/Hackwar
Well, I only made a note of it in an existing doc, so that other people can save the time that I lost (nothing negative intended). Until things are settled, how should I inform component developers? (I would have liked such a note, so I imagine others still do.)
This is the current note:
"Joomla 3.3 Note: Since Joomla 3.3, one should rather extend the interface JComponentRouterInterface and handle the routing and parsing similar as below, but via the methods of this interface. This will also evade the now fixed one way dash-to-colon issue."
P.S. Don't have time to check those PR's really, but crowdfunded joomla routing? Respect!
You are missing a few points here. First of all, the issue that you are talking of is not one-way. The router always took all segments and replaced colons with dashes when building the URL. It then replaces the first dash with a colon again when parsing the URL. So this is in fact consistent and not a bug. Its a stupid way to do things, but it got implemented that way, so we have to live with it.
The second point is, that from the point those PRs are merged, the component routers will be written in an entirely different way and you will be able to write them a LOT shorter.
So any real documentation effort on this right now will rather confuse people than help them, since it changes in a few days/weeks.
I'm still get colon when implemented the JComponentRouterInterface ? (joomla 3.5.1)
Do you have idea?
JComponentRouterInterface does NOT replace the stuff for you. With your information so far, I can't help you. besides that, this is not a help channel, but an issue tracker. Please ask on joomla-dev-general or in the forum.
This is indeed the case and due to backwards compatibility reasons, this can not be fixed in the 3.x series for function based component routers. However, if you look at com_content for example in 3.3.6, you see that the router is now a class and that parse() and build() are methods of that class. When in a class, the parse method expects the segments to be unchanged.
Long story short: If you change your component router to a class based router, this issue is gone and thus this is not a bug (anymore).