Closed endel closed 10 years ago
If I got this right, yeah! You can do it! Method calls will be static though:
<?php
// Will call a static showProfile on the UsersController class.
$router->get('/users/*', ['UsersController', 'showProfile']);
Respect\Rest looks for valid callable arguments. On PHP there is a lot of ways of creating callable arguments. It's not Respect specific:
// Calls the static DateTime::createFromFormat
call_user_func(['DateTime', 'createFromFormat'], 'd-m-Y', '10-10-2012');
You'll need to create the instance for yourself if you don't want static calls:
<?php
$usersController = new UsersController;
// Will call a standard showProfile on the UsersController class.
$router->get('/users/*', [$usersController, 'showProfile']);
Using this way to bind your controller classes also don't need the Routable
interface, because the calls are treated as callbacks.
Awesome @alganet, that's it. Thanks!
Hello,
It would be nice to allow binding routes to specific controller methods, just like Laravel does. It isn't possible today, right?
Example: (docs)
I'm aware of the existence of illuminate/routing, I've already tried it, but Respect/Rest is far more performative due it's lightweight nature.