本文实例讲述了Laravel框架搜索分页功能。分享给大家供大家参考,具体如下:
控制器controller
代码语言:javascript复制/**
* 文章搜索
*
* @author YING
* @param void
* @return void
*/
public function mesArticleSearch()
{
//接值
$input=Input::get();
//调用模型查询
//实例化类
$cate=new Article();
//调用自定义方法 查询分类
$artInfo=$cate- searchAll($input);
//从session的用户名
$username=session('user_name');
//实例化类
$cate=new Category();
//调用自定义方法 查询分类
$cateInfo=$cate- selectAll();
return view('admin.article',['username'= $username,'artInfo'= $artInfo,'cateInfo'= $cateInfo,'cate_id'= $input['cate_id'],'title'= $input['title']]);
}
模型model
代码语言:javascript复制/**
* 文章搜索
*
* @author YING
* @param void
* @return void
*/
public function searchAll($input)
{
//判断
if($input['cate_id']!=0&&$input['title']!=""){
return $this- join('user','u_id','=','user.Id')
- join('category','article.cate_id','=','category.cate_id')
- select('user_name','cate_name','article.*')
- where('category.status','0')
- where(array('category.cate_id'= $input['cate_id']))
- where('title','like','%'.$input['title'].'%')
- orderBy('article.sort','DESC')
- paginate(3);
}else if($input['cate_id']!=0&&$input['title']==""){
return $this- join('user','u_id','=','user.Id')
- join('category','article.cate_id','=','category.cate_id')
- select('user_name','cate_name','article.*')
- where('category.status','0')
- where(array('category.cate_id'= $input['cate_id']))
- orderBy('article.sort','DESC')
- paginate(3);
}else if ($input['cate_id']==0&&$input['title']!=""){
return $this- join('user','u_id','=','user.Id')
- join('category','article.cate_id','=','category.cate_id')
- select('user_name','cate_name','article.*')
- where('category.status','0')
- where('title','like','%'.$input['title'].'%')
- orderBy('article.sort','DESC')
- paginate(3);
}else{
return $this- join('user','u_id','=','user.Id')
- join('category','article.cate_id','=','category.cate_id')
- select('user_name','cate_name','article.*')
- where('category.status','0')
- orderBy('article.sort','DESC')
- paginate(3);
}
}
比较low
视图view
代码语言:javascript复制<div class="list-page" style="margin-left: 400px"
{{$artInfo- appends(['cate_id' = $cate_id])- appends(['title' = $title])- render()}}
</div
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。