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.

Data Model Questions /

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

Controller routing


Go to End


3 Posts   1284 Views

Avatar
codemonkey88

Community Member, 24 Posts

24 October 2013 at 11:05pm

Please can somebody help me get started with routing? I tried the documentation, but it doesn't seem to be working.

I have this code

class Brand extends DataObject {
static $db = array("Name" => "VarChar(200)");
static $has_many = array("Products" => "Product");
}

class Brand_Controller extends Controller
{
static $allowed_actions = array('test');
	public function test($request)
	{
	return $this->renderWith('Page');
	}
}

I would expect this to create a page at www.mysite.com/brand/test but I just get a 404. What am I missing?

Avatar
kinglozzer

Community Member, 187 Posts

25 October 2013 at 3:41am

Hi,

Your code would create a page at www.mysite.com/Brand_Controller/test. To tell SilverStripe that 'brand' should route to your Brand_Controller, you need to add a route for it. See here for an example (assuming you're using 3.1): http://doc.silverstripe.org/framework/en/topics/controller

Avatar
codemonkey88

Community Member, 24 Posts

13 November 2013 at 4:23am

Ok, that figures. I ended up using DataObject::get from a page class anyway, but useful for future ref.