When querying paging in a closure, the paging conditions for printing SQL are not attached. By default, all are displayed.
年年年年年2019-03-06 11:43:58
0
5
1361
Why can the teacher write it directly and use it? When I tested it, everything was displayed. The paging conditions were ignored directly. When printing the sql, it showed that there were no paging conditions.
Just change the position of that code:
public function index()
{
//Category information display
$cateId=Request::param('cate_id') : >assign('cateName',$res->name);
$artList=Db::name('zh_article')
;where('cate_id',$cateId)
through ',$artList);
}
else{
$artList=Db::name('zh_article')
->order('create_time','desc')->paginate(3);
$this->view->assign('cateName','All articles');
}
$this->view->assign('artList',$artList);
return $this->fetch();
}
抱歉,应该是这样的:
if (isset($cateId))
{
$artList=Db::table('zh_article')
->where('status',1)
->where('cate_id',$cateId)
->order('create_time','desc')->paginate(3);
}
$artList=Db::table('zh_article')
->where('status',1)
->where('cate_id',$cateId)
->order('create_time','desc')->paginate(3);
$this->view->assign('artList',$artList);
return $this->fetch();
if (isset($cateId))
{
$artList=Db::table('zh_article')
->where('status',1)
->where('cate_id',$cateId)
->order('create_time','desc')->paginate(3);
}
$artList=Db::table('zh_article')
->where('status',1)
->order('create_time','desc')->paginate(3);
$this->view->assign('artList',$artList);
return $this->fetch();
这样子可以出来
The same question