Warum hat der Lehrer es direkt geschrieben und es kann verwendet werden? Beim Drucken der SQL wurde angezeigt, dass es keine Paging-Bedingungen gab
那个代码换一下位置就可以了:
public function index(){ //分类信息显示 $cateId=Request::param('cate_id'); //如果存在这个分类 if (isset($cateId)){ $res=ArtCate::get($cateId); $this->view->assign('cateName',$res->name); $artList=Db::name('zh_article') ->where('status',1) ->where('cate_id',$cateId) ->order('create_time','desc')->paginate(3); $this->view->assign('artList',$artList); } else{ $artList=Db::name('zh_article') ->where('status',1) ->order('create_time','desc')->paginate(3); $this->view->assign('cateName','全部文章'); } $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();
这样子可以出来
同问
那个代码换一下位置就可以了:
public function index()
{
//分类信息显示
$cateId=Request::param('cate_id');
//如果存在这个分类
if (isset($cateId)){
$res=ArtCate::get($cateId);
$this->view->assign('cateName',$res->name);
$artList=Db::name('zh_article')
->where('status',1)
->where('cate_id',$cateId)
->order('create_time','desc')->paginate(3);
$this->view->assign('artList',$artList);
}
else{
$artList=Db::name('zh_article')
->where('status',1)
->order('create_time','desc')->paginate(3);
$this->view->assign('cateName','全部文章');
}
$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();
这样子可以出来
同问