Jump to:

23493 Posts in 19013 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Framework: Setting the Root Controller Route on 3.1

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

Page: 1
Go to End
Author Topic: 830 Views
  • purplespider
    Avatar
    Community Member
    81 Posts

    Framework: Setting the Root Controller Route on 3.1 Link to this post

    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

  • cumquat
    Avatar
    Community Member
    198 Posts

    Re: Framework: Setting the Root Controller Route on 3.1 Link to this post

    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

  • purplespider
    Avatar
    Community Member
    81 Posts

    Re: Framework: Setting the Root Controller Route on 3.1 Link to this post

    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

  • cumquat
    Avatar
    Community Member
    198 Posts

    Re: Framework: Setting the Root Controller Route on 3.1 Link to this post

    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

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Framework: Setting the Root Controller Route on 3.1 Link to this post

    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

  • kinglozzer
    Avatar
    Community Member
    142 Posts

    Re: Framework: Setting the Root Controller Route on 3.1 Link to this post

    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

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Framework: Setting the Root Controller Route on 3.1 Link to this post

    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

    830 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.