Php Laravel在视图中显示错误
如果验证失败,我将执行以下操作:Php Laravel在视图中显示错误,php,error-handling,laravel,laravel-4,Php,Error Handling,Laravel,Laravel 4,如果验证失败,我将执行以下操作: return Redirect::back()->with('validation', $validation->errors->all()); 我还使用: $restful = true; 因此,当我在get_edit()-我得到一个错误,生成视图时没有$validation变量,当我在post_edit()-这一切都没问题,因为它返回一个带有错误的重定向 我的看法是: <? foreach($validation as $e):
return Redirect::back()->with('validation', $validation->errors->all());
我还使用:
$restful = true;
因此,当我在get_edit()
-我得到一个错误,生成视图时没有$validation变量,当我在post_edit()
-这一切都没问题,因为它返回一个带有错误的重定向
我的看法是:
<? foreach($validation as $e): ?>
<div><?= $e; ?></div>
<? endforeach; ?>
因此,变量存在但为空,但现在出现了一个新问题,每次执行此筛选器后,它都会覆盖生成我的post_edit()
的$validation
,而且我在视图中看到一个变量$errors
,但始终为空,我不知道如何使用它,您能帮助我吗
所以很快我的问题是:
public function get_edit($id)
{
//generate my view with all nessesary data, but i can't generate here an error variable
// or its better to put it in one place to globally share it in the views, otherwise i am //getting an error
}
public function post_edit($id)
{
//validating $_POST data, if there is an error redirect it back to the get_edit() WITH a //variable containing errors
}
你看过文件了吗
您可以使用returnredirect::back()->withErrors($validation)代码>
在视图中,始终可以使用重定向('register')->withErrors($validator)$errors
,而无需将它们绑定到视图
public function get_edit($id)
{
//generate my view with all nessesary data, but i can't generate here an error variable
// or its better to put it in one place to globally share it in the views, otherwise i am //getting an error
}
public function post_edit($id)
{
//validating $_POST data, if there is an error redirect it back to the get_edit() WITH a //variable containing errors
}