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

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里