Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED ]Routing example for YAML Config / DataObject needed

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

Page: 1
Go to End
Author Topic: 567 Views
  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    [SOLVED ]Routing example for YAML Config / DataObject needed Link to this post

    Hi there,

    I've been reading through the docs regarding routing and i am a bit confused.
    I currently have the following:

    -------------------------------------------------
    mysite/code/controllers/Customer.php
    -------------------------------------------------

    class Customer_Controller extends Controller {

       public static $allowed_actions = array ();

       public function init() {
       parent::init();
       return $this->renderWith('Customer');
       }

    //Set up URL handler
    private static $url_handlers = array(
    'customer/$Action/$ID/$Name'
    );

    }

    # i want to be able to render the Customer.ss template if the user types the following url..... mysite/customer/
    # i am trying to avoid hooking onto the Page Class because there will be alot of data and i dont want to involve SiteTree
    # as far as i can see from the docs i am supposed to be able to do this either via the YAML config file or $url_handlers

    I am not sure how to configure the YAML file to do this.

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5503 Posts

    Re: [SOLVED ]Routing example for YAML Config / DataObject needed Link to this post

    In your routes.yml you need to define the rule you current have as a url_handler. The configuration defined in url_handler is used *once* the controller has matched.

    ---
    Name: myroutes
    After: framework/routes#coreroutes
    ---
    Director:
    rules:
    'customer//$Action/$ID/$Name': 'Customer_Controller'

    (Note forum strips whitespace, you'll need to 2 space each for lines)

    You can remove the url_handler for your class (as it's not doing anything special in your instance)

  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Re: [SOLVED ]Routing example for YAML Config / DataObject needed Link to this post

    Thanks...this worked well

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