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.

Customising the CMS /

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

Default $Controller//$Action routing question


Go to End


3 Posts   4118 Views

Avatar
markguinn

Community Member, 27 Posts

4 December 2009 at 5:33am

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

Avatar
Willr

Forum Moderator, 5523 Posts

4 December 2009 at 9:30am

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",
));

Avatar
markguinn

Community Member, 27 Posts

17 December 2009 at 1:39pm

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