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

Framework: Setting the Root Controller Route on 3.1


Go to End


15 Posts   4979 Views

Avatar
purplespider

Community Member, 89 Posts

12 May 2013 at 5:26am

Edited: 12/05/2013 5:29am

I've been playing with a framework only install of SS3 and am putting together my first web app.

I'm having a bit of a problem setting the routes to my make controller the root one, in SS3.1-beta3.

The following routes.yml is working fine:

---
Name: customroutes
After: framework/routes#coreroutes
---
Director:
  rules:
    'wishes//$Action/$ID': 'WishController'

mydomain.com/wishes displays my index action.
mydomain.com/wishes/view/8 views an item using my view action.

However, I'd like to remove the "/wishes" section from the URL, so that mydomain.com/ and mydomain.com/view/8 will work the same way.

So I tried updating my routes.yml to the following:

---
Name: customroutes
After: framework/routes#coreroutes
---
Director:
  rules:
    '': 'WishController'
    '//$Action/$ID': 'WishController'

But while mydomain.com/ now displays my index action fine,
mydomain.com/view/8 just says: "No URL rule was matched".

Can someone please advice what the routes should be to achieve this?

Thanks
James

Avatar
cumquat

Community Member, 201 Posts

18 June 2013 at 10:24pm

Hi James,

Did you get an answer to this? Also if you wouldn't mind could you put up the code for your controller, im just starting to play with framework and am trying to find as much info as possible on how to move forward, i've had some help here but i think the main issue is my lack of knowledge of the core fundamentals.

One thing that strikes me is maybe you could use a htaccess rewrite rule to solve your problem?

Mick

Avatar
purplespider

Community Member, 89 Posts

18 June 2013 at 10:34pm

Hi Mick,

I actually gave up, and just rolled back to 3.0.

Here's my current code though:

routes.yml: http://spdr.me/PVM
WishController: http://spdr.me/NKmm

RootController: http://spdr.me/iSpO
Added to _config.php: http://spdr.me/77ZK

The RootController stuff just makes sure that pages such as /Security/login etc have all their theme requirements.

The site is live at www.mypebblewishes.com

James

Avatar
cumquat

Community Member, 201 Posts

18 June 2013 at 10:42pm

Hi James,

many thanks for this, gives me something to play with, didn't realise there was such a difference between 3 and 3.1 in the framework.

Thanks again oh and nice site by the way.

Mick

Avatar
Mo

Community Member, 541 Posts

14 February 2014 at 6:41am

Hi All,

I would be very interested in knowing what the issue with this is as well, as I am having the same issues in 3.1, but would prefer to stick to 3.1 if poss?

I have tried quite a few different version of routes and nothing seems to work properly...

Cheers,

Mo

Avatar
kinglozzer

Community Member, 187 Posts

15 February 2014 at 12:16am

Hi all,

This is definitely possible in 3.1, the key is adding in extra routes between #rootroutes and #coreroutes. You can do this with something like:

---
Name: 'rootroutes'
---
Director:
	rules:
		'$Action/$ID': 'MyController'

This will route http://mysite.com/someaction/123 to MyController with an action of 'someaction' and an ID of '123'. It's important that you name your routes 'rootroutes' so they're inserted in the correct place.

Loz

Avatar
Mo

Community Member, 541 Posts

17 February 2014 at 10:41pm

Hmm, I wasn't aware that you could do this... I will give it a go next chance I get and see what happens :-).

Cheers,

Mo

Avatar
neilcreagh

Community Member, 136 Posts

15 March 2017 at 1:15am

I'm really struggling with this. I have a recruitment site that I'd like to display jobs (dataobjects) from the root eg. website.com/job/ID.
The action is 'job'
This code below works but results in website.com/job/job/ID

---
Name: mysiteroutes
After: framework/routes#coreroutes
---
Director:
  rules:
    'job//$Action/$ID': 'MainJobsPage_Controller'

I've tried kinglozzers code exactly as above, and every combination of Before: framework/routes#coreroutes and After: framework/routes#rootroutes

Any ideas? I'm running 3.5.2

Go to Top