Closed quickliketurtle closed 10 years ago
This would be a useful feature, it could mean having a single handler for any collection, but with multiple methods, e.g. call list and show on the same collection and both with a http get request
Using the same handler for viewing a collection and viewing an item can already be achieved simply:
<?php
class CollectionHandler {
public function get($id = null) {
if (is_null($id)) {
// No ID, view collection
} else {
// View item specified by ID
}
}
}
Toro::serve(array(
'collection' => 'CollectionHandler',
'collection/:numeric' => 'CollectionHandler'
));
Hi Martin, this lets you use more restful methods (index, show, create, edit, update, destroy...) and custom methods (processHash...).
That being said, i didn't ask it this was useful before submitting the PR so i understand it not being merged.
HI @quickliketurtle. No worries. It’s more just to keep the barrier of entry for ToroPHP low.
I’m very fond of resource controllers in Laravel (which have methods named as you’ve described: index
, show
, create
, edit
, update
, and destroy
, so don’t know if that’s your inspiration), but those names require a more in-depth knowledge of REST conventions; whereas most developers (should) know the different between GET and POST, and when to use each appropriately.
Add ability to override the default behavior of calling method matching HTTP request type with custom method by appending '@methodName' to the handler. Updated readme with example usage.