yii 框架分页
2017-08-25 10:38
113 查看
dao 模式:1
$name=yii::$app->request->get('name');
$descs=yii::$app->request->get('descs');
$string = yii::$app->db->createCommand("select * from upload where name like '%$name%' and descs like '%$descs%'")->queryAll();
$count = count($string);
$pages = new Pagination(["totalCount" => $count, "pagesize" => 2]);
$list = yii::$app->db->createCommand("select *from upload where name like '%$name%' and descs like '%$descs%' limit $pages->offset,$pages->limit")->queryAll();
dao 模式:2
public function actionLists($page = 1){
// $data = Yii::$app->db->createCommand('select * from dao')->queryAll();
// return $this->render("lists",['data'=>$data]);
$sql = "select * from dao";
$res = Yii::$app->db->createCommand($sql)->queryAll();
//分页
//总条数
$count = count($res);
//每页条数
$size = 2;
//总页数
$sumPage = ceil($count/$size);
//偏移量
$limit = ($page-1)*$size;
//上一页
$prev = $limit-1 < 0 ? 1 : $page-1;
//下一页
$next = $limit+1 > $sumPage ? $sumPage : $page+1;
$sql1 = "select * from dao limit $limit,$size";
$data = Yii::$app->db->createCommand($sql1)->queryAll();
$page = '<a href="index.php?r=daosts&page=1">首页</a> | <a href="index.php?r=daosts&page='.$prev.'">上一页</a> | <a href="index.php?r=daosts&page='.$next.'">下一页</a> | <a href="index.php?r=daosts&page='.$sumPage.'">尾页</a>';
return $this->render('lists',['data'=>$data,'page'=>$page]);
}
dao 模式:3
public function actionIndex()
{
//echo qqqq;die;
// $command = Yii::$app->db->createCommand('SELECT * FROM `image`');
// $arr = $command->queryAll();
//print_r($arr);die;
$where['search']=Yii::$app->request->get('search');
$where['nums']=Yii::$app->request->get('nums');
$query=new Query();
if(!empty($where['search'])){
$query->andFilterWhere(
['like','uname',$where['search']]
);
}
if(!empty($where['nums'])){
$query->andFilterWhere(
['like','id',$where['nums']]
);
}
$count=$query->from('image')->all();
$pages = new Pagination(['totalCount' =>$query->count(),'pageSize'=>'4']);
$users = $query->offset($pages->offset)->limit($pages->limit)->all();
//高亮
foreach($users as $k=>$v){
$users[$k]=str_replace($where['search'],"<font color='red'>".$where['search']."</font>",$v);
}
foreach($users as $k=>$v){
$users[$k]=str_replace($where['nums'],"<font color='red'>".$where['nums']."</font>",$v);
}
return $this->render('index',
['model'=>$users,
'where'=>$where,
'pages'=>$pages]);
}
}
$name=yii::$app->request->get('name');
$descs=yii::$app->request->get('descs');
$string = yii::$app->db->createCommand("select * from upload where name like '%$name%' and descs like '%$descs%'")->queryAll();
$count = count($string);
$pages = new Pagination(["totalCount" => $count, "pagesize" => 2]);
$list = yii::$app->db->createCommand("select *from upload where name like '%$name%' and descs like '%$descs%' limit $pages->offset,$pages->limit")->queryAll();
dao 模式:2
public function actionLists($page = 1){
// $data = Yii::$app->db->createCommand('select * from dao')->queryAll();
// return $this->render("lists",['data'=>$data]);
$sql = "select * from dao";
$res = Yii::$app->db->createCommand($sql)->queryAll();
//分页
//总条数
$count = count($res);
//每页条数
$size = 2;
//总页数
$sumPage = ceil($count/$size);
//偏移量
$limit = ($page-1)*$size;
//上一页
$prev = $limit-1 < 0 ? 1 : $page-1;
//下一页
$next = $limit+1 > $sumPage ? $sumPage : $page+1;
$sql1 = "select * from dao limit $limit,$size";
$data = Yii::$app->db->createCommand($sql1)->queryAll();
$page = '<a href="index.php?r=daosts&page=1">首页</a> | <a href="index.php?r=daosts&page='.$prev.'">上一页</a> | <a href="index.php?r=daosts&page='.$next.'">下一页</a> | <a href="index.php?r=daosts&page='.$sumPage.'">尾页</a>';
return $this->render('lists',['data'=>$data,'page'=>$page]);
}
dao 模式:3
public function actionIndex()
{
//echo qqqq;die;
// $command = Yii::$app->db->createCommand('SELECT * FROM `image`');
// $arr = $command->queryAll();
//print_r($arr);die;
$where['search']=Yii::$app->request->get('search');
$where['nums']=Yii::$app->request->get('nums');
$query=new Query();
if(!empty($where['search'])){
$query->andFilterWhere(
['like','uname',$where['search']]
);
}
if(!empty($where['nums'])){
$query->andFilterWhere(
['like','id',$where['nums']]
);
}
$count=$query->from('image')->all();
$pages = new Pagination(['totalCount' =>$query->count(),'pageSize'=>'4']);
$users = $query->offset($pages->offset)->limit($pages->limit)->all();
//高亮
foreach($users as $k=>$v){
$users[$k]=str_replace($where['search'],"<font color='red'>".$where['search']."</font>",$v);
}
foreach($users as $k=>$v){
$users[$k]=str_replace($where['nums'],"<font color='red'>".$where['nums']."</font>",$v);
}
return $this->render('index',
['model'=>$users,
'where'=>$where,
'pages'=>$pages]);
}
}
相关文章推荐
- yii框架中,搜索的表单和后台执行,以及分页
- Yii框架结合sphinx,Ajax实现搜索分页功能示例
- yii DAO yii框架增删改查 分页 验证码 框架自带表单
- yii框架中的两表联查+分页
- Yii框架分页实现方法详解
- Yii框架结合sphinx,Ajax实现搜索分页功能示例
- YII框架中自带的表单,搜索,分页代码的实现
- yii框架所搜分页
- YII框架中自带的表单,搜索,分页代码的实现
- yii框架分页的实现
- yii框架查询分页展示
- yii 框架中的上传 分页
- 关于js框架 dwz 与 yii的的分页 以及筛选的结合
- YII框架中自带的表单,搜索 4000 ,分页代码的实现
- yii框架中分页url重写rewrite达到各参数变伪静态链接,即不出现?和&的参数
- yii框架中的分页
- 【Yii框架】YII分页组件
- yii框架引入coreseek 分页
- yii2.0框架分页
- Ajax无刷新分页偷懒版(该例子写于YII框架下,其他框架请自行修改部分代码)