如何在 Laravel 4 中制作通用路线
How to make Generic Route in Laravel 4
如何制作这样的路由器
Route::any("/{controller}/{method}/{param}", "$controller@$method");
这样我就可以为大多数情况下的约定定义一个路由,而不是在路由文件中指定每个方法 http://example.com/controller/method/param
在Laravel 4.2中你可以使用[隐式控制器][1]。
Laravel allows you to easily define a single route to handle every action in a controller. First, define the route using the Route::controller method:
Route::controller('users', 'UserController');
The controller method accepts two arguments. The first is the base URI the controller handles, while the second is the class name of the controller. Next, just add methods to your controller, prefixed with the HTTP verb they respond to:
class UserController extends BaseController {
public function getIndex()
{
//
}
public function postProfile()
{
//
}
}
https://laravel.com/docs/4.2/controllers#implicit-controllers
像这样:
Route::any('{controller}/{method}/{param}', function ($controller, $method, $param) {
return call_user_func_array($controller.'::'.$method, $param);
});
如何制作这样的路由器
Route::any("/{controller}/{method}/{param}", "$controller@$method");
这样我就可以为大多数情况下的约定定义一个路由,而不是在路由文件中指定每个方法 http://example.com/controller/method/param
在Laravel 4.2中你可以使用[隐式控制器][1]。
Laravel allows you to easily define a single route to handle every action in a controller. First, define the route using the Route::controller method:
Route::controller('users', 'UserController');
The controller method accepts two arguments. The first is the base URI the controller handles, while the second is the class name of the controller. Next, just add methods to your controller, prefixed with the HTTP verb they respond to:
class UserController extends BaseController {
public function getIndex()
{
//
}
public function postProfile()
{
//
}
}
https://laravel.com/docs/4.2/controllers#implicit-controllers
像这样:
Route::any('{controller}/{method}/{param}', function ($controller, $method, $param) {
return call_user_func_array($controller.'::'.$method, $param);
});