Yii2.0 多条件搜索 带分页
方法一
在控制器中
public function actionShow(){
$where['title']=Yii::$app->request->get('title');
$where['content']=Yii::$app->request->get('content');
$query=new Query();
$query->from('votes');
// votes 是表名
if(!empty($where['title'])||!empty($where['content'])){
$query->andFilterWhere(
['like','title',$where['title']]
)->orFilterWhere(
['like','content',$where['content']]
);
}
$users=$query->from('votes')->all();
$pages = new Pagination(['totalCount' =>$query->count(),'pageSize'=>'2']);
$users = $query->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('show',['data'=>$users,'where'=>$where,'pages'=>$pages]);
}
在V层
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use yii\widgets\LinkPager;
?>
<?php
$form=ActiveForm::begin([
'action'=>Url::toRoute(['show']),
'method'=>'get',
]);
echo '姓名'," ",Html::input('text','title');
echo '简介'," ",Html::input('text','content');
echo Html::submitButton('提交');
ActiveForm::end();
echo "<br/>";
echo "<br/>";
?>
显示在v层的分页
<?php
echo LinkPager::widget([
'pagination'=>$pages,
'nextPageLabel'=>'下一页',
'firstPageLabel'=>'首页'
])
?>
方法二(不带分页 是另外一种方法)
public function actionShow(){
$titles=Yii::$app->request->post('title');
$content=Yii::$app->request->post('content');
$where=;
if($titles!=""){
$where.=" and title like '%$titles%'";
}
if($content!=""){
$where.=" and content like '%$content%'";
}
$sql="select * from votes where $where";
$users=Yii::$app->db->createCommand($sql)->query();
return $this->render('show',['data'=>$users]);
}
Yii2.0 多条件搜索 带分页的更多相关文章
- CodeIgniter框架多条件搜索查询分页功能解决方案
最近在用ci框架写功能的时候,需要用到分页功能,本来寻常的数据结果分页是比较简单的,但是这次写的功能是多条件搜索查询分页,就有点难度了,看官方手册下面评论好多人问, 正常的分页功能例子是这样的: $t ...
- yii2.0表单自带验证码
Yii2.0的自带的验证依赖于GD2或者ImageMagick扩展. 使用步骤如下: 第一步,控制器: 在任意controller里面重写方法
- thinkphp5.0多条件模糊查询以及多条件查询带分页如何保留参数
1,多条件模糊查询 等于:map[‘id′]=array(‘eq′,100);不等于:map[‘id′]=array(‘eq′,100);不等于:map[‘id’] = array(‘neq’,100 ...
- YII2.0多条件查询升级版
$query = self::find()->andFilterWhere(['v_type' => $v_type])->andFilterWhere(['like', 'a_na ...
- think php 多条件检索+自带分页+多条件搜索标红分页
//视图<form action="/homework/homework/index" method="get"> <input type=& ...
- Node.js、express、mongodb 实现分页查询、条件搜索
前言 在上一篇Node.js.express.mongodb 入门(基于easyui datagrid增删改查) 的基础上实现了分页查询.带条件搜索. 实现效果 1.列表第一页. 2.列表第二页 3. ...
- spring boot jpa 多条件组合查询带分页的案例
spring data jpa 是一个封装了hebernate的dao框架,用于单表操作特别的方便,当然也支持多表,只不过要写sql.对于单表操作,jpake可以通过各种api进行搞定,下面是一个对一 ...
- [moka同学笔记]三、Yii2.0课程笔记(魏曦老师教程)关联字段增加搜索
关联字段增加搜索 post表关联adminuser表,通过post.author_id adminuser.id关联,在YII2.0生成搜索,关联字段搜索时,需要输入关联字段author的id才能搜 ...
- 关于TP5.0搜索后分页
使用$Model->where($where)->paginate($page,$count);的时候如果点击下一页会出现条件重置问题,经过测试可以使用Db::name('data') - ...
随机推荐
- OSI参考模型初识
纪念我曾今热爱的数通(^o^). 1.osi参考模型 2.数据的封装和解封装 3.主机和主机间通信
- Super Jumping! Jumping! Jumping!杭电1087
Description Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumpi ...
- extjs中,datefield日期,点击输入框弹出日期,禁止手动输入
之前用readonly:true连日期也选不了了,editable:false也不行,最后用事件监听实现 栗子如下: { xtype: 'datefield', fieldLabel: '创建结束时间 ...
- wcf测试工具
WCF测试工具-WcfStorm WCF测试工具-WcfStorm http://www.wcfstorm.com/wcf/home.aspx WcfStorm is a dead-simple, ...
- Comparer<T> IComparer<T> IComparable<T>
Comparer<T>.Default Property Comparer<T>.Default doesn't use your FooComparer class. It ...
- 谜题 UVA227
这道题目还是不难的,但是要注意gcc里面gets已经不能用了,用gets_s还是可以的,尽管我并不知道有什么区别 #include<stdio.h>#include<stdlib.h ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- 用户输入密码隐藏之getpass的使用
有的时候,比如商城登录的时候,我希望输入的时候我的密码不为明文,如何实现呢? 这里就需要利用getpass模块中的getpass方法.注意,需要在linux上或者windows下运行,在pycharm ...
- IIS下无法访问.ini后缀文件
环境: windows server 2003 R2.IIS6 问题: 无法访问网站下的.ini后缀的文件 解决办法: 添加ini文件的MIME映射,让IIS能下载扩展名是ini的文件 添加路径:相应 ...
- cxf 报错:java.lang.NoSuchMethodError: org.apache.ws.commons.schema.XmlSchemaCollection.read(Lorg/w3c/dom/Document;Ljava/lang/String;)
由于没有仔细查看官方提供的文档,由jdk版本不一致导致的出错: http://cxf.apache.org/cxf-316-release-notes.html 自己使用的是jdk1.8. 报Exce ...