[英]Route not found error in Laravel 4 with form on Home page
I have made a form on home page in hello.blade.php file , with form value 我在hello.blade.php文件的主页上创建了一个表单,其中包含表单值
{{ Form::open(array('route' => 'home/addguest',
'class' => "form-horizontal")) }}
I have defined a method named addGuest()
in HomeController
which adds values in database and sends email. 我在
HomeController
定义了一个名为addGuest()
的方法,它在数据库中添加值并发送电子邮件。
I am getting error on home page as 我在主页上收到错误
ErrorException Route [home/addguest] not defined. (View: /var/www/laravel/app/views/hello.blade.php)
Route.php has Route.php有
Route::post('Home/addGuest', array('uses' => 'HomeController@addGuest'));
Route::get('/home', function()
{
return View::make('home');
});
What value shall I define in form attribute to post this data and save that in the database? 我应该在form属性中定义什么值来发布这些数据并将其保存在数据库中?
Shall I change the form post target or shall I change the homecontroller
method? 我应该更改表单发布目标,还是应该更改
homecontroller
方法?
In route.php 在route.php中
Route::post('Home/addGuest', array('uses' => 'HomeController@addGuest'));
Should be 应该
Route::post('Home/addGuest', array('as' => 'addguest', 'uses' => 'HomeController@addGuest'));
The "as" is the naming of the route, that you are refering to in the form. “as”是您在表单中引用的路径的命名。 Be sure to update the Forms route to just "addguest" as well.
一定要将Forms路由更新为“addguest”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.