Gabe
Gabe

Reputation: 1183

PHP AltoRouter Call a method on Controller

Trying to call a method on a controller but this wont work on AltoRouter

$router->map( 'GET', '/users/[i:id]/', 'UserController#showDetails' );

What I'm doing wrong?

PS:There is no example on how to get the parameters on the Controller method either.

Upvotes: 2

Views: 1901

Answers (1)

swatkins
swatkins

Reputation: 13630

The route is correct - assuming the UserController is in the global namespace. If not, make sure to use the fully qualified namespace in the string.

$router->map( 'GET', '/users/[i:id]/', 'App\UserController#showDetails' );

Then, in your controller, you will access the parameter like this:

public function showDetails ($id) {

}

The [i:id] means to match an integer as a variable named id.

Upvotes: 1

Related Questions