【发布时间】:2013-08-17 01:38:49
【问题描述】:
我真的是 Laravel 的新手,我正在尝试让一个表单正常工作。
所以我有一个页面(管理员/索引),其中只有一个表单,其中包含映射到 AdminController@test 的路由。表单提交正常,但随后我收到 NotFoundHttpException。 :(
index.blade.php 中表单构建器的代码是:
@extends('layouts.master')
@section('title')
Admin
@stop
@section('content')
{{ Form::open(array('route' => 'test', 'method' => 'get')) }} <!-- Works with AdminController@index -->
{{ Form::text('info') }}
{{ Form::close() }}
@stop
有问题的路线是:
Route::get('/admin/test/' , array( 'as' => 'test' ,
'uses' => 'AdminController@test'));
而有问题的控制器是:
class AdminController extends BaseController{
public function index(){
return View::make('admin.index');
}
public function test(){
error_log('Yay!');
}
}
就像我说的,在 admin/index 上的简单表单提交,但它没有提交给控制器,只是提交给 NotFoundHttpException。
编辑: 表单的 HTML 如下所示:
<form method="GET" action="http://localhost/showknowledge/admin/test/"
accept-charset="UTF-8">
<input name="info" type="text">
</form>
【问题讨论】:
-
您是否尝试过将表单直接指向控制器上的操作?
{{ Form::open(array('action' => 'AdminController@test', 'method' => 'get')) }} -
是的,刚刚尝试过同样的问题。 :(
-
哦,等一下,一旦表单被提交,在请求的过程中会发生什么?它会将
Yay写入日志,对吗? -
表单的 HTML 在页面上是什么样子的?上面可以加吗?
-
啊好的,你能这样声明你的路线吗?
Route::get('admin/test/' , array( 'as' => 'test' , 'uses' => 'AdminController@test'));
标签: exception laravel laravel-4 laravel-routing