silverstripe-framework/docs/en/changelogs/rc/3.2.0.md
Ingo Schommer 957469d770 API Removed auto-routing of controller name
Use custom routing rules to achieve this effect (see changelog)
2013-02-18 14:29:47 +01:00

1.7 KiB

3.2.0 (unreleased)

Overview

CMS

Framework

  • API: Removed URL routing by controller name

Details

API: Removed URL routing by controller name

The auto-routing of controller class names to URL endpoints has been removed (rule: '$Controller//$Action/$ID/$OtherID': '*'). This increases clarity in routing since it makes URL entpoints explicit, and thereby simplifies system and security reviews.

Please access any custom controllers exclusively through self-defined routes. For controllers extending Page_Controller, simply use the provided page URLs.

:::php
class MyController extends Controller {
	static $allowed_actions = array('myaction');
	public function myaction($request) {
		// ...
	}
}

Create a new file mysite/_config/routes.yml (read more about the config format). Your controller is now available on http://yourdomain.com/my-controller-endpoint, after refreshing the configuration cache through ?flush=all.

:::yaml
---
Name: my-routes
After: framework/routes#coreroutes
---
Director:
	rules:
		'my-controller-endpoint//$Action' : 'MyController'

The auto-routing is still in place for unit tests, since its a frequently used feature there. Although we advise against it, you can reinstate the old behaviour through a director rule:

:::yaml
---
Name: my-routes
After: framework/routes#coreroutes
---
Director:
	rules:
		'$Controller//$Action/$ID/$OtherID':  '*'