【发布时间】:2014-06-03 15:30:22
【问题描述】:
我今天刚开始尝试 Laravel 4.1,我不得不使用 Laravel 4.0 的教程,所以我不得不对代码的某些部分进行故障排除。 有一个部分我无法解决,我需要一些帮助。
这些是涉及的路线:
Route::get('authors/{id}/edit', array('as'=>'edit_author', 'uses'=>'AuthorsController@get_edit'));
Route::put('authors/update', array('uses'=>'AuthorsController@put_update'));
这些是控制器中的操作:
public function get_edit($id){
return View::make('authors.edit')->with('title', 'Edit Author')->with('author', Author::find($id));
}
public function put_update(){
$id = Input::get('id');
$author = array(
'name' => Input::get('name'),
'bio' => Input::get('bio'),
);
$validation = Author::validate($author);
if ($validation->fails()){
return Redirect::route('edit_author', $id);
}else{
Author::update($id, $author);
return Redirect::route('view_author', $id);
}
}
请注意,在路由中我使用的是 {id} 而不是 (:any),因为后者对我不起作用。
在我的浏览器上,get_edit 函数起初运行正常,但是当我单击提交按钮并且它应该执行 put_update 时,无论它应该将我重定向到 view_author 还是返回到 edit_author,它只会给我一个 NoFoundHttpException。
作为附加信息,我使用默认的 .htacces 是这个:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
【问题讨论】:
标签: php redirect laravel frameworks