Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Controller routing

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

Page: 1
Go to End
Author Topic: 298 Views
  • codemonkey88
    Avatar
    Community Member
    13 Posts

    Controller routing Link to this post

    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?

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: Controller routing Link to this post

    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

  • codemonkey88
    Avatar
    Community Member
    13 Posts

    Re: Controller routing Link to this post

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

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