Silverstripe Version: 3.2
Question:
I’m trying to add a route to a legacy SS3.2 website, which already has a number of custom routes defined, which point to existing controller functions.
here’s the mysite/routes.yml file I’m working with:
---
Name: myroutes
After: framework/routes#coreroutes
---
Director:
rules:
'home//$Action/$ID' : 'Page_Controller'
'search//results' : 'SearchPage_Controller'
'search//resultsnewroute' : 'SearchPage_Controller'
The last line is mine, everything else was there before.
Here’s the a snippet of the SearchPage_Controller
file:
class SearchPage_Controller extends Page_Controller
{
private static $allowed_actions = array("results", "resultsnewroute");
.... etc
public function results($request)
{
...existing code here
}
public function resultsnewroute($request)
{
exit('Hello World');
}
search//results routes to a function results($request){}
in SearchPage_Controller, this existing code works fine.
- I’ve created a
resultsnewroute($request){}
function also in the SearchPage_Controller - however I never see ‘Hello World’ and my request seemingly never reaches this function. - I have run
/dev/build
after updating the yml file, but my route is never recognised and gives a 404 - If I break the yml file, by adding line breaks in the middle of the content,
/dev/build
throws an error (which is what I would expect) - If I edit the yml file, changing the existing routes, and run
/dev/build
, the site continues to work (I would expect it to break)
What am I doing wrong?
Many thanks in advance