17487 Posts in 4473 Topics by 1978 members
|Go to End|
8 June 2007 at 1:06pm
Hi, I've got a site I'm working on that has pages for each region of New Zealand. I made a RegionHolder that contains Region objects (that inherit from Page).
What I want is for the URL "/region/waikato" to display the Waikato region/page. I was thinking Director::addRules() would do it, but I'm not sure how. Should I try direct it to Region_Controller, or Region? Or something else that makes the correct Region object? Or maybe it would be best to just go to a page called "region", which has a method to fetch data from a Region object?
Does this make sense?
10 June 2007 at 1:46pm
if your region subclasses Page/SiteTree, then the region is automatically avaiable at /waikato (or otherwise specified in the URLSegment). The alternative way of showing it would be to create a "show"-function on your Region_Controller and link to /region/show/waikato. leaving out the action makes the whole thing more complicated: you have to override defaultAction() in your Region_Controller, which is called when no method called "waikato" is found in the class. in there, you call e.g. $this->show() - and work with $this->urlParams['Action'] to get your region-name (as specified by the default director-rule)
11 June 2007 at 3:17pm Last edited: 11 June 2007 3:47pm
I think I'm just going to use /waikato for the URL and forget the /region/.
It got me thinking, though...would SilverStripe benefit from a more complex routing system for people like me who want to do odd things with specific URLs? Or am I just missing the proper way to do it?
I was just thinking something that would work like:
'region/$RegionName/$Action' => array(
'Controller' => 'RegionController',
'Action' => 'showMap'
It would use the extra array to set defaults, for example if you went to /region/greater_putaruru it would run the showMap() method of the RegionController, and give it "greater_putaruru", but if you went to /region/greater_putaruru/listMembers it would override the default action and run the listMembers() method instead. Good idea, bad idea, or completely unnecessary?
PS: code formatting in forum posts would be pretty handy too
11 June 2007 at 5:21pm Last edited: 11 June 2007 5:22pm
"PS: code formatting in forum posts would be pretty handy too " - matts working on it
11 June 2007 at 5:24pm
sounds like a good idea. btw, we usually fallback to index() if an action is missing in the called controller.
11 June 2007 at 8:56pm
Given that index() is the default action, the added complexity doesn't seem justified.
The current system would allow for this, provided you rename showMap() to index().
'region/$RegionName/$Action' => 'RegionController',
I'm reluctant to add complexity to these deeply core modules unless there is a large value in them - otherwise we'll get a bloated system.
12 June 2007 at 2:37pm
I guess it wouldn't let you do anything you can't do already, but it's an extra tool for customising your URLs...and if there's one thing I'm finicky about it's my URLs.
Although if I really want it I can always just add the functionality myself.
|Go to Top|