gpt4 book ai didi

php - Laravel 4, ->withInput(); = undefined offset : 0

转载 作者:可可西里 更新时间:2023-10-31 22:06:22 30 4
gpt4 key购买 nike

我在这里和 Laravel 论坛都进行了长时间的搜索,但我找不到这个问题的答案。 ->withInput() 吐出一个 Undefined offset: 0

对于上下文:

Controller

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(); 页面加载正常。

最终目标是将我从上一个问题 Undesired result from db:raw 中得到的答案汇总并有一个页面加载“过滤”表单并在重新加载时显示相关结果并记住表单中的选择。

提前致谢。

更新:根据评论我更新了 Controller 和路由,结果仍然相同:

路由.php

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

&

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

Controller

 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 。

在 View 上调用 withInput($data) 有完全不同的效果;它将以下键值对传递给您的 View :'input' => $data(您收到错误,因为您没有将任何数据传递给该函数)

要获得您想要的效果,请在创建 View 之前调用 Input::flash(),而不是调用 withInput()。这应该允许您在 View 中使用 Input::old() 函数来访问数据。

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

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

翻译成

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

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

$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);

关于php - Laravel 4, ->withInput(); = undefined offset : 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027830/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com