EDIT: D'oh, I feel silly now. As you can see below, I was assuming this would be passed in via ->getVars() and failed to realize SilverStripe uses it's own custom ->param('name') and ->params() methods. I'm leaving this embarrassing post here in the off chance that someone else ends up making the same mistake. I actually figured it out by diving into SS core code and totally glazed over the documentation. </facepalm>
---
Hmm, I'm having the same issue but this doesn't work for me at all. It seems that simply passing your own custom parameters to the root index is practically impossible if at least not properly documented. It's certainly not working intuitively based on the normal syntax. Basically I just want to do something along these lines:
--
Name: mysite-routes
After: framework/routes#coreroutes
---
Director:
rules:
'api/my-endpoint': 'MyAPI_Controller'
There are no DataObject's involved, just a plain route to a controller. In this case, I want to simply have URL's like api/my-endpoint/foo and have foo automatically be the variable I define, e.g. ID in ->getVars(). Unfortunately, the following doesn't work (not even if I point it to another action):
<?php
class MyAPI_Controller extends Controller {
private static $allowed_actions = [
'index'
];
private static $url_handlers = [
'$ID' => 'index', // Doesn't work
'//$ID' => 'index', // Also doesn't work
];
public function index(SS_HTTPRequest $request) {
// ... nothing...
print_r(request->getVars());
}
}
What am I doing wrong, or, is this some kind of bug?