Laravel 4,-> withInput(); =未定义偏移量:0 [英] Laravel 4, ->withInput(); = Undefined offset: 0

查看:85
本文介绍了Laravel 4,-> withInput(); =未定义偏移量:0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里和Laravel论坛上都进行了冗长的搜索,但是我找不到这个问题的答案. ->withInput()咳嗽Undefined offset: 0.

I have had a lengthy search both here and the Laravel forums, but i can't find an answer to this problem. ->withInput() coughs up an Undefined offset: 0.

对于上下文:

控制器

public function getJobs()

        {
            $position_options = DB::table('jposition')->lists('friendly','id');
            $category_options = DB::table('jcategory')->lists('friendly','id');
            $location_options = DB::table('jlocation')->lists('friendly','id');



            $result = $query->get();
            return View::make('jobsearch.search', array('position_options' => $position_options, 'category_options' => $category_options, 'location_options' => $location_options))->withInput();

        }

查看

<form action="{{ action('JobsearchController@getJobs') }}" method="post">
  <div class="row">
    <div class="large-8 columns">
      <input type="text" name="realm" placeholder="Keywords/Skills" />
    </div>
    <div class="large-4 columns">
       {{ Form::select('category', $category_options , Input::old('category')) }}
    </div>
  </div>
  <div class="row">

    <div class="large-4 columns">
      {{ Form::select('location', $location_options , Input::old('location')) }}
    </div>


    <div class="large-4 columns">
      {{ Form::select('type', $position_options , Input::old('type')) }}
    </div>
    <div class="large-4 columns">
       <input type="submit" value="Search" style="width:100%; padding-top: .5rem;
padding-bottom: .5rem;" class="button border-btn" />
      </div>


</div>
</form>

现在,根据文档,这里应该没有问题,并且如果删除了->withInput();,则页面可以正常加载.

Now according to the documentation there should not be an issue, and the page loads fine if the ->withInput(); is removed.

最终目标是加入我从上一个问题中得到的答案 db的不良结果: raw ,只有一个页面可以加载过滤"表单,并在重新加载时显示相关结果,并记住表单中的选择.

The end goal is to roll in the answer that i received from my previous question Undesired result from db:raw and have a single page that loads the "Filtering" form and displays the relevant results on the reload and remembers the selections in the form.

谢谢.

更新: 发表评论后,我已经更新了控制器和路由,结果仍然相同:

UPDATE: Following a comment i have updated the controller and routes, still same result:

routes.php

routes.php

Route::get('jobs/search', 'JobsearchController@getSearch');

&

Route::post('jobs/search', 'JobsearchController@getJobs');

控制器

 public function getSearch()
        {
                    $position_options = DB::table('jposition')->lists('friendly','id');
            $category_options = DB::table('jcategory')->lists('friendly','id');
            $location_options = DB::table('jlocation')->lists('friendly','id');

            return View::make('jobsearch.search', array('position_options' => $position_options, 'category_options' => $category_options, 'location_options' => $location_options));
        }

        public function getJobs()

        {
            $position_options = DB::table('jposition')->lists('friendly','id');
            $category_options = DB::table('jcategory')->lists('friendly','id');
            $location_options = DB::table('jlocation')->lists('friendly','id');


            return View::make('jobsearch.search', array('position_options' => $position_options, 'category_options' => $category_options, 'location_options' => $location_options))->withInput();

        }

推荐答案

withInput()不能以您认为的方式工作.它只是重定向的功能,而不是View的功能.

withInput() doesn't work the way you think it does. It's only a function of Redirect, not View.

在View上调用withInput($data)具有完全不同的效果;它将以下键值对传递给您的视图:'input' => $data(由于未将任何数据传递给该函数而出现错误)

Calling withInput($data) on View has a completely different effect; it passes the following key value pair to your view: 'input' => $data (you get an error because you're not passing any data to the function)

要获得所需的效果,请在生成视图之前调用Input::flash(),而不要调用withInput().这样一来,您就可以在视图中使用Input::old()函数来访问数据.

To get the effect that you want, call Input::flash() before making your view, instead of calling withInput(). This should allow you to use the Input::old() function in your view to access the data.

或者,您可以简单地将Input::all()传递到视图,并在视图中使用input[]数组:

Alternatively, you could simply pass Input::all() to your view, and use the input[] array in your view:

View::make(...)->withInput(Input::all());

翻译成

View::make(...)->with('input', Input::all());


关于您的评论,我建议这样做:


As for your comment, I recommend doing it like so:

$position_options = DB::table('jposition')->lists('friendly','id');
$category_options = DB::table('jcategory')->lists('friendly','id');
$location_options = DB::table('jlocation')->lists('friendly','id');
$category = Input::get('category');
$location = Input::get('location');
$type = Input:: get('type'); 

$data = compact('position_options', 'category_options', 'location_options', 'category', 'type', 'location');

return View::make('jobsearch.search', $data);

这篇关于Laravel 4,-&gt; withInput(); =未定义偏移量:0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆