2014-03-30 129 views
1

我正在阅读codebright。尝试在数据检索部分。但我在路由上失败了。laravel 4 route post throw new NotFoundHttpException

我把我的laravel安装在wamp上。

这是我的代码。

form.blade.php

<form action="{{ url('/') }}" method="post"> 

    <input type="hidden" name="foo" value="bar" /> 
    <input type="hidden" name="baz" value="boo" /> 

    <input type="submit" value="Send" /> 

</form> 

routes.php文件

Route::post('/', function() { 
    $data = Input::all(); 
    var_dump($data); 
}); 


Route::get('post-form', function() { 
    return View::make('form'); 
}); 

它显示一个错误页面,并说: “throw new NotFoundHttpException;

但之后我添加了一个尾部斜杠行动。像这样:"action={{url('/')/}}"。它工作正常。我不知道哪里错了。 .htaccess或我需要设置virtual machine

在此先感谢。

+0

但是使用Route :: get是可以的。但是使用Route :: post()失败了。 – iceman126

回答

0

名称的路线: 可以说你有路线“/”

在你的路由文件 Route::get('/',array('as'=>'Home'); 家是路线

去形成刀片和 $网址的名称= URL ::路线( '家'); // $网址是您路线

{{Form::open(array('method'=>'post','action'=>$url))}} 

检查 Laravel-docs-Named_Routes

+0

感谢您的回答。但是在我做完之后。它仍然显示错误。我认为由斜线引起的问题。因为我在行动结束时加了'/',一切都很好。 – iceman126

+0

THX。我发现了这个问题。它应该是返回var_dump($ data)。对不起,我的愚蠢问题。 – iceman126