php – Laravel 5路由分页url编码问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Laravel 5路由分页url编码问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2682字,纯文字阅读大概需要4分钟。
内容图文
![php – Laravel 5路由分页url编码问题](/upload/InfoBanner/zyjiaocheng/825/192e75e8fd724ef79ccf0501ab9c195c.jpg)
我构建了一个laravel 5应用程序,现在我正在测试它如何处理不同的输入.因此我遇到了一个奇怪的问题.在标题中我有一个搜索字段.它返回结果,分页为10.
问题
如果用户输入一个字母,例如英文的“e”,一切正常.但是,当用户输入一个字母时,例如保加利亚语中的“e” – 结果的第一页显示正确,当用户点击第2页时,保加利亚语中“е”搜索中的查询将更改为“е”并且没有显示更多结果.这是该网站的实际链接. http://podobri.eu
我想这与编码有关,但我看不出我做错了什么.
这是实际的代码
路线
Route::get('/search', [
'uses' => '\Podobri\Http\Controllers\SearchController@getResults',
'as'=>'search.results',
]);
SearchController
public function getResults(Request $request){
$query = $request->input('query');
$comments = Comment::where(function($query){
return $query;
})->orderBy('created_at', 'desc')->get();
if(!$query || $query==''){
return view('problems.index')->with('comments', $comments);
}
$problems = Problem::where(DB::raw("CONCAT(problem_title, ' ', problem_description)"), 'LIKE', "%$query%")
->orWhere('location', 'LIKE', "%$query%")
->orWhere('category', 'LIKE', "%$query%")
->orderBy('created_at', 'desc')->paginate(10);
Carbon::setLocale('bg');
return view('search.results')
->with('comments', $comments)
->with('problems', $problems)
->with('title', 'Резултати за "'."$query".'" | Подобри')
->with('description', 'Резултати за "'."$query".'" в системата на Подобри');
}
视图
@foreach($problems as $problem)
<div>
@include('problems.partials.problemblock')
</div>
@endforeach
<!-- Paginating-->
{!! $problems->appends(Request::except('page'))->render() !!}
搜索表单
<form action="{{ route('search.results') }}" role="search" class="navbar-form navbar-left head-form-responsive">
<div class="form-group">
<input type="text" required id='searchQuery' title="Търсете за проблеми" value="{{ Request::input('query') }}" name="query" class="form-control"
placeholder="Търсете за проблеми"/>
</div>
<button type="submit" id='searchBtn' class="btn btn-default">Търсете</button>
</form>
解决方法:
它看起来像你的问题正在发生,因为paginator附加一个带有一些奇怪重定向的尾部斜杠(不确定你们是否使用自定义htaccess).例如,如果您搜索e,则这是URL:
http://podobri.eu/search?query=e
但是,第二页的URL是这样的:
http://podobri.eu/search/?query=e&page=2
注意?查询前面的斜杠.如果你删除斜杠,它的工作原理.那么,你怎么解决这个问题呢?
这实际上是几个月前修复的.你可以在这里看到这个提交:https://github.com/laravel/framework/commit/806fb79f6e06f794349aab5296904bc2ebe53963
因此,如果您使用的是L5.1或5.2,则可以运行composer update,它将自行修复.但是,如果你使用5.0,它似乎仍然有这个bug,所以你可以使用setPath方法,并尝试这样做:
{!! $problems->setPath('')->appends(Request::except('page'))->render() !!}
内容总结
以上是互联网集市为您收集整理的php – Laravel 5路由分页url编码问题全部内容,希望文章能够帮你解决php – Laravel 5路由分页url编码问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。