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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Controller with only $ID, no $Action

Go to End

3 Posts   1133 Views


Community Member, 46 Posts

24 April 2014 at 3:19am

Edited: 24/04/2014 3:20am

I have a page called video. I want /video/abc123 to play a video with ID abc123.

I also want the page 'video' to be translatable. So it won't always be the exact word 'video'.

I previousy had it working when it didn't have to be translatable yet, but right now I'm forced to make the URL longer: /video/yt/abc123. That's because I'm using the standard $Action/$ID/$Parameter pattern, allowing me to translate the page name (can't figure out how to do it in the config otherwise). So in the example /video/yt/abc123, yt is my "action", which I have set to allowed.

But I would like to go back to just /[PageTitle]/abc123. I tried getting that to work by using the $Action as the video ID, but that doesn't work because it just says Page not Found then (despite 'allowing all actions'), because it doesn't know I'm trying to do something with the parameter rather than making it load a page. I suppose 'allow all actions' only works for functions that have actually been defined, and of course I don't have a function for each video ID.

Is there a way around this? Perhaps something with routes, but how to get around the translated page name then? Or can I in another way force the url handler to stop looking for pages, and push all parameters to just that video page (with no action checks)?


Community Member, 344 Posts

25 April 2014 at 3:15am

Edited: 25/04/2014 3:21am

class VideoPage_Controller extends Page_Controller {
	private static $url_handlers = array(
		'$ID!' => 'show',
	private static $allowed_actions = array(

	function show() {
		$params = $this->getURLParams();

		if (!empty($params['ID']) && is_numeric($params['ID'])) {
			// get video by id
		return $this->httpError(404);


Community Member, 46 Posts

25 April 2014 at 3:58am

Excellent, thank you! I didn't immediately get it to work, but a flush solved that (should be obvious, I know). It didn't actually need the 'index' in the allowed_actions array.

I had not understood that documentation completely because the first part of all the patterns that are mentioned, are always actions that are in the allowed_actions array. In my opinion, the drivethrough example there doesn't even make sense, because 'drivethrough' is an allowed action, while the function being called is order, not drivethrough! Right? Someone should probably change that bit in the documentation then.

Thank you for clearing it up with your answer :)