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.

Data Model Questions

Controller routing


Reply

3 Posts   401 Views

Avatar
codemonkey88

24 October 2013 at 11:05pm Community Member, 13 Posts

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

25 October 2013 at 3:41am Community Member, 146 Posts

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

13 November 2013 at 4:23am Community Member, 13 Posts

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