Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Default $Controller//$Action routing question

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

Page: 1
Go to End
Author Topic: 2830 Views
  • markguinn
    Avatar
    Community Member
    13 Posts

    Default $Controller//$Action routing question Link to this post

    I apologize if this is a stupid question. I was unable to find anything else about this on the forums. The documentation says in several places that there should be a default routing rule to map "/team/signup" to "Team_Controller::signup()", provided that controller exists. It sounds to me like you don't need to set up a Director rule to facilitate such a mapping, and when I look at the rules via ?debug=1, I see a rule on there that SHOULD map that way as far as I can tell, but I haven't been able to get it to work. Can someone confirm that the documentation is correct? I'm looking at:

    http://doc.silverstripe.org/doku.php?id=recipes:controllers (under Simulate Pages with Controllers)

    And also:

    http://doc.silverstripe.org/doku.php?id=execution-pipeline (under Controllers and actions)

    Thanks.
    Mark

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Default $Controller//$Action routing question Link to this post

    As long as you have a Page in the CMS with the classname 'TeamPage' and the URLSegment 'team' then yes that it automatic. Basically the /team/ action looks for the controller on a page with the URL 'team'. If you don't have a page which provides this mapping then you'll have to use the Classname as the URL like '/Team_Controller/signup/' if you want the /team/ url and don't have a page mapping then you'll have to write a custom routing action like this in your _config

    Director::addRules(100, array(
       'team/$Action/$ID' => "Team_Controller",
    ));

  • markguinn
    Avatar
    Community Member
    13 Posts

    Re: Default $Controller//$Action routing question Link to this post

    Thanks for the reply. You're correct that /Team_Controller/ seems to work. I would suggest the documentation be updated in the following ways:

    1. On this page: http://doc.silverstripe.org/doku.php?id=execution-pipeline

    Change: "You can access the following controller-method with /team/signup"
    To: "You can access the following controller-method with /Team_Controller/signup"

    2. On this page: http://doc.silverstripe.org/doku.php?id=recipes:controllers

    The information all appears to be correct, but I would add some clarification on this line: "More native URL-Layout (”/team/create” instead of “/myteampage/create”)" - something along the lines of "More native URL-Layout (”/team/create” instead of “/myteampage/create” - Please note the default routing would be /Team_Controller/create unless you set up custom routing)".

    3. There was one other place where the documentation was explicitly wrong, but I can't find it. It was actually even worse because it had controller action methods declared as "function myaction($param1, $param2){}" which, as I understand is also wrong.

    Thanks,
    Mark

    2830 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.