我正在Laravel 4应用程序中创建搜索功能。
它运行良好,因为它运行良好,这是非常好的功能,这是我在邮政编码字段中进行搜索(例如)并单击搜索时唯一的事情。
我希望搜索的值保留在文本输入中。就像将值设置为标准PHP / HTML中的php变量一样。
我已经包含了控制器功能和一个文本输入字段,供您在下面查看。任何帮助将不胜感激,谢谢。
public function postSearch()
{
$search_order_from_date = Input::get('search_order_from_date');
$search_order_to_date = Input::get('search_order_to_date');
$search_order_type = Input::get('search_order_type');
$search_order_status = Input::get('search_order_status');
$search_order_agent = Input::get('search_order_agent');
$search_order_assessor = Input::get('search_order_assessor');
$search_order_postcode = Input::get('search_order_postcode');
$orders = DB::table('orders')
// ->where('order_date', '>=', $search_order_from_date, 'and', 'order_date', '<=', $search_order_to_date, 'or')
->orWhere('type', '=', $search_order_type)
->orWhere('epc_status', '=', $search_order_status)
->orWhere('agent', '=', $search_order_agent)
->orWhere('assessor', '=', $search_order_assessor)
->orWhere('postcode', '=', $search_order_postcode)
->orderBy('order_date', 'DESC')
->paginate();
Session::put('search', 'search query');
$users = User::all();
$userType = Session::get('type');
$perms = DB::table('permissions')->where('user_type', $userType)->first();
$this->layout->content = View::make('orders.index', compact('orders'), compact('perms'));
}
{{Form :: text('search_order_postcode',null,array('class'=>'form-control','placeholder'=>'Order Postcode'))}}
您可以将search_order_postcode传递到您的视图。
$this->layout->content = View::make('orders.index', compact('orders', 'search_order_postcode'), compact('perms'));
将其添加到索引视图或创建初始搜索表单视图的任何位置,这样就不会出现错误(如果不存在)。
编辑:还将其从控制器传递到搜索视图。
$search_order_postcode = (isset($search_order_postcode) && $search_order_postcode !== '') ? $search_order_postcode : null;
然后在您看来:
// Search_order_postcode is either the value it was given or null
{{ Form::text('search_order_postcode', $search_order_postcode, array('class'=>'form-control', 'placeholder'=>'Order Postcode')) }}
重复冲洗其他输入,或将它们存储在数组中,以免膨胀您的view :: make,但这是个人喜好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句