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

Framework: Setting the Root Controller Route on 3.1


Reply

7 Posts   854 Views

Avatar
purplespider

12 May 2013 at 5:26am (Last edited: 12 May 2013 5:29am), Community Member, 81 Posts

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

18 June 2013 at 10:24pm Community Member, 198 Posts

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

18 June 2013 at 10:34pm Community Member, 81 Posts

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

18 June 2013 at 10:42pm Community Member, 198 Posts

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

14 February 2014 at 6:41am Community Member, 509 Posts

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

15 February 2014 at 12:16am Community Member, 146 Posts

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

17 February 2014 at 10:41pm Community Member, 509 Posts

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