dpwgzi7987
2013-04-06 13:43
浏览 96
已采纳

Laravel在视图中显示错误

if my validation fails I do this:

return Redirect::back()->with('validation', $validation->errors->all());

also I am using:

$restful = true;

so when I am on get_edit() - I'am getting an error that there are no $validation variable when generating my view, when in post_edit() - its all okay because its returns a redirect with errors...

this is my view:

<? foreach($validation as $e): ?>

<div><?= $e; ?></div>

<? endforeach; ?>

undefined variable $validation, right now I'am trying to put it on the Router::before

Route::filter('before', function()
{
    View::share('validation', array());
});

so the variable exists but is empty, but now arises a new problem, everytime after this filter executes it overrides those $validation that generates my post_edit(), also i've seen a variable $errors in my view but is ever empty, i don't how to use it, can you help me?

so shortly my problem is:

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

}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • duanou8504 2013-04-06 20:35
    最佳回答

    Did you read the docs? http://laravel.com/docs/5.0/validation#error-messages-and-views

    You can use return Redirect::back()->withErrors($validation); In your views, you can always use redirect('register')->withErrors($validator)$errors, without binding them to the view.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题