With Laravel 5 I'm not able to setup get route parameters.
有了Laravel 5,我无法设置获取路线参数。
My route is setup like this:
我的路线是这样设置的:
Route::get('test', 'TestController@test');
And my TestController looks like this:
我的TestController是这样的:
public function test(Request $request)
{
var_dump($request->input('foo'));
}
When I browse to that route with a parameter
当我用参数浏览到那条路径时
/test?foo=bar
the result is NULL.
结果为空。
Can anybody tell me what I'm doing wrong?
有人能告诉我我做错了什么吗?
The Input::get('foo') syntax doesn't work either (and is not even mentioned in the documentation for L5).
输入:get('foo')语法也不起作用(甚至在L5的文档中都没有提到)。
Update:
更新:
I'm using Apache as webserver.
我使用Apache作为webserver。
I have also tried
我也试过
$request->get('foo')
and a route like this
像这样的路线
Route::get('test/{foo?}', 'TestController@test');
with the same URL and still get null.
使用相同的URL,仍然得到null。
Update 2:
更新2:
The documentation of L5 gives examples for routes like this:
L5的文档给出了如下路线的例子:
/test/bar
instead of
而不是
/test?foo=bar
In L4 it was possible to browse to routes with GET like
在L4中,可以用GET like来浏览路线。
/test?foo=bar&id=2&user=admin
or changing the order
或更改订单
/test?id=2&user=admin&foo=bar
with one and the same route
有一条相同的路线
Route::get('test', 'TestController@test');
and all you had to do was get it with
你所要做的就是得到它
Input::get('user')
But with L5 it wouldn't be possible to change the order of parameters when you have to use slashes in the routes like
但是对于L5,当你需要在像这样的路径中使用斜线时,不可能改变参数的顺序
Route::get('test/{id}/{user}/{foo}', 'TestController@test');
Is this really a big downgrade for routes in L5?
这真的是L5航线的降级吗?
3 个解决方案
#1
1
The problem was the .htaccess
file, I used an edited one where the parameters didn't get send.
问题是。htaccess文件,我使用了一个编辑过的参数没有发送的地方。
With the default .htaccess
file that comes with the Framework everything works!
使用框架附带的默认.htaccess文件,一切正常!
#2
0
Would you try this?
你试试这个吗?
use Request;
public function test(Request $request)
{
var_dump($request->get('foo'));
}
#3
0
In laravel 5 you can put a param into controller method like this:
在laravel 5中,可以将param放入控制器方法中:
public function test(Request $request, $foo) { }
公共功能测试(请求$ Request, $foo) {}
with route - Route::get('test/{foo}', 'TestController@test');`
使用route - route:get('test/{foo}', 'TestController@test');
#1
1
The problem was the .htaccess
file, I used an edited one where the parameters didn't get send.
问题是。htaccess文件,我使用了一个编辑过的参数没有发送的地方。
With the default .htaccess
file that comes with the Framework everything works!
使用框架附带的默认.htaccess文件,一切正常!
#2
0
Would you try this?
你试试这个吗?
use Request;
public function test(Request $request)
{
var_dump($request->get('foo'));
}
#3
0
In laravel 5 you can put a param into controller method like this:
在laravel 5中,可以将param放入控制器方法中:
public function test(Request $request, $foo) { }
公共功能测试(请求$ Request, $foo) {}
with route - Route::get('test/{foo}', 'TestController@test');`
使用route - route:get('test/{foo}', 'TestController@test');