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

[SOLVED ]Routing example for YAML Config / DataObject needed


Go to End


3 Posts   2172 Views

Avatar
Optic Blaze

Community Member, 190 Posts

5 October 2013 at 9:49am

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

Avatar
Willr

Forum Moderator, 5523 Posts

6 October 2013 at 5:42pm

Edited: 06/10/2013 5:42pm

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)

Avatar
Optic Blaze

Community Member, 190 Posts

8 October 2013 at 11:51am

Thanks...this worked well