Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Overrule #modelascontrollerroutes in routes.yml


Go to End


5 Posts   1504 Views

Avatar
martimiz

Forum Moderator, 1391 Posts

8 August 2013 at 1:48am

Edited: 08/08/2013 1:53am

Hi all

This has been bugging me for the best part of a year now, and I'm beginning to think the use of wildcards in YAML isn't as innocent as it seems.

For my LanguagePrefix module, I'm still trying to overrule/replace the modelascontrollerroutes, without success. If I'm correct, this is how the framework/cms routes are prioritized (and I placed my rule where I think it should be):

rootroutes -> Before *   
modelascontrollerroutes -> Before: *, After: rootroutes
languageprefixroutes -> Before: ???, After: ???
coreroutes -> Before: *, After: rootroutes, modelascontrollerroutes
adminroutes -> Before: *, After: rootroutes, coreroutes, modelascontrollerroutes
legacycmsroutes -> After: adminroutes

Obviously I want my lanuageprefixroutes after the modelascontrollerroutes, but before the coreroutes. After is easy, but Before always triggers the conflict error, whatever I try. Below one of many tries:

---
Name: 'languageprefixroutes'   
After: 'cms/routes#modelascontrollerroutes'
Before: 'framework/routes#coreroutes'         <-- look, no wildcards
---

Has anyone ever succeeded in doing this? Can it actually be done?

Thanks, Martine

Avatar
Willr

Forum Moderator, 5523 Posts

11 August 2013 at 6:10pm

I think the Wildcard approach is not the right one. If you remove the Before: * for coreroutes, adminroutes does that solve your issue? I wonder if these should only define after segments and let modules conclude if they need to be placed after *.

Avatar
martimiz

Forum Moderator, 1391 Posts

12 August 2013 at 1:36am

Edited: 12/08/2013 1:37am

Hi Will,
Thanks. I guess if I remove the Before:'*' from framework and cms routes, i won't have a problem positioning my rule after #coreroutes and before #adminroutes.

I absolutely think framework and cms routes can easily be set up without the use of wildcards, and that would definitely solve the problem for other modules.

I posted this on core dev some months ago, but unfortunately there was no response at that time :)

https://groups.google.com/forum/m/#!searchin/silverstripe-dev/Routes.yml/silverstripe-dev/njFeb3ZJ_jc

The documentation states that priority is determined based on the number of wildcards used, where Before '*' stands for three wildcards, Before:'#adminroutes' stands for two, so something like Before 'framework/routes#adminroutes' should at least have presedence, but that doesn't seem to be that simple.

Maybe I should set it up again, do all the test and submit a pull...

Avatar
Willr

Forum Moderator, 5523 Posts

12 August 2013 at 7:25pm

Tests sound like the best place to start!

Avatar
Schippie

Community Member, 38 Posts

13 October 2014 at 9:27pm

Has this ever been resolved in some way or form?

Right now i am trying to get my own routes after those of the #modelascontrollerroutes since i am dealing with legacy qr codes that all went to the <domain>/***** url while i want this to be just the homepage and have those routes redirect to the new structure /qr/****** but whatever i do i either break all the other pages (Except the home page) or have everything redirect to the the wrong controller.

What i would like to do is:

Have all pages work like normal so if their is a page /more-information/ it should go to the modelascontrollerroutes but if none of those are found it should go to the homepage with a url like /****** (6 characters) if it has more then those 6 characters or something else i would then also still like to have the ability to send them to a 404 not found page.

Anybody have any suggestions?