简体   繁体   English

PHP AltoRouter在Controller上调用方法

[英]PHP AltoRouter Call a method on Controller

Trying to call a method on a controller but this wont work on AltoRouter 试图在控制器上调用方法,但这不适用于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. PS:没有关于如何在Controller方法上获取参数的示例。

The route is correct - assuming the UserController is in the global namespace. 路线是正确的 - 假设UserController在全局命名空间中。 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 . [i:id]表示将integer作为名为id的变量进行匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM