I've written a controller that doubles as something resembling a RESTful API to handle AJAX requests. I'd like to have this controller have a "list" action to return a JSON array of data objects (e.g. a script does a GET request to "<root url>/product/list" and gets back an array of products in JSON), but I come to find that "list" is a reserved word in PHP so I can't seem to create a method with that name. Is there some sort of workaround or should I think of a different name for the action?
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.
You can't use list as a method name. But you can use $url_handlers to map a action name to a specific method.
private static $url_handlers = array(
'list//$ID/$OtherID' => 'items',
);
private static $allowed_actions = array(
'items',
);
public function items() {
return 'list';
}