【发布时间】:2015-01-09 07:30:28
【问题描述】:
我在 laravel 中的表单有问题, 所以我的项目结构是:
controllers/
administration/
NewsController.php
在 NewsController 我有一个方法调用:postCreate():
public function postCreate(){
$validator = Validator::make(Input::all(), \News::$rules);
if($validator->passes()){
$news = new \News();
$news->title = Input::get('title');
$news->content = Input::get('content');
$news->author = Input::get('author');
$news->type = Input::get('type');
$image = Input::file('file');
$filename = time().".".$image->getClientOriginalExtension();
$path = public_path('content/images/' . $filename);
Image::make($image->getRealPath())->resize(468,249)->save($path);
$news->image = 'content/images/'.$filename;
$news->save();
return Redirect::to('/administration/news/add')
->with('message','Succes');
}
return Redirect::to('/administration/news/add')
->with('message','Error')
->withErrors($validator)
->withInput();
}
我的表单有动作:
{{ Form::open(array('url'=>'administration/news/create', 'files'=>true)) }}
{{ Form::close() }}
我的路线:
Route::post('/administration/news/create', array('uses'=>'App\Controllers\Administration \NewsController@postCreate'));
但是当我提交时出现错误:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
我不明白我的问题出在哪里。
【问题讨论】:
-
运行 php artisan routes 以查看每个路由是否已正确声明。
-
最好将表单发送到操作。这样 Laravel 会自动将表单设置为
post或get。 -
你使用的是什么命名空间?
标签: php laravel laravel-4 php-5.3 laravel-routing