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.

General Questions /

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

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

Overrule #modelascontrollerroutes in routes.yml


Reply


5 Posts   387 Views

Avatar
martimiz

Forum Moderator, 1132 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, 5513 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, 1132 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, 5513 Posts

12 August 2013 at 7:25pm

Tests sound like the best place to start!

Avatar
Schippie

Community Member, 37 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?