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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Routing question


Go to End


800 Views

Avatar
Dorsai

Community Member, 12 Posts

15 September 2015 at 10:32am

Edited: 15/09/2015 10:33am

Hi,
I am hoping someone might be able to point out where I am going wrong with some routing.

I have the following controller:

class Authors_Controller extends Page_Controller {

	private static $allowed_actions = array('authors');

	private static $url_handlers = array(
		'bookshop/authors//$Action' => 'authors'
	);

	public function authors(){
    
		if($this->request->param('Action') > 0){
			$output = '[output a specfic author based on the value of Action]';
		}	 else {
			$output = '[output other content about authors]';
		}
		return $output;
    
	}
}

and in the template
<div class="row">$authors</div>

if the url in the browser is /bookshop/authors I get the second output fine ('[output other content about authors]'), but when I add any number to the url i.e. /bookshop/authors/45 I get a 404 Page Not Found

I have tried putting the routing rule in the config.yml as opposed to using $url_handlers and that makes no difference to the result.

Any pointers on what I am doing wrong?