一、视图

<div class="form-horizontal">
<?php $form = $this->beginWidget('CActiveForm', array('id' => 'course', 'action' => '/admin/mp/')); ?>
<div class="form-group">
<div class="col-md-2">
<?php echo $form->textField($model, 'title', array('class' => 'form-control', 'placeholder' => '标题')); ?>
</div>
<div class="col-md-2">
<?php echo $form->textField($model, 'name', array('class' => 'form-control', 'placeholder' => '名字')); ?>
</div>
<div class="col-md-2">
<?php echo $form->dropDownList($model, 'type', array('' => '类别') + $model->getTypeList(), array('class' => 'form-control', 'placeholder' => '类别')); ?>
</div>
<div class="col-md-1">
<?php echo CHtml::submitButton('查询', array('class' => 'btn btn-default btn-primary')); ?>
</div>
<div class="col-md-1">
<a href="/admin/user/edit" class="btn btn-default">添加矩阵</a>
</div>
</div>
<?php $this->endWidget(); ?>
</div>

二、模型

class Mp extends CActiveRecord
{ const AFFAIRS = 1;
const BUSINESS = 2; public function tableName()
{
return 'mp';
} public static function model($className = __CLASS__)
{
return parent::model($className);
} public function getTypeList()
{
return array(
self::AFFAIRS => '政务',
self::BUSINESS => '商业',
);
} public function getTypeName()
{
$arr = $this->getTypeList();
if (isset($arr[$this->type])) {
return $arr[$this->type];
}
return '未知';
}
public function rules()
{
return array(
array('title,name,type', 'safe', 'on' => 'search'),
);
} }

三、控制器

 public function actionIndex()
{
$model = new Mp('search');
if (isset($_POST['Mp'])) {
$model->setAttributes($_POST['Mp']);
}
$criteria = new CDbCriteria();
$criteria->addSearchCondition('title', $model->title);
$criteria->addSearchCondition('name', $model->name);
$criteria->addSearchCondition('type', $model->type);
$count = Mp::model()->count($criteria);
$pager = new CPagination($count);
$pager->pageSize = $this->pageSize;
$pager->applyLimit($criteria); $list = Mp::model()->findAll($criteria);
$this->render('index',array('model'=>$model,'list'=>$list,'pager'=>$pager)); }

Yii 查询 搜索的更多相关文章

  1. lucene多条件查询”搜索—BooleanQuery

    /** * “多条件查询”搜索—BooleanQuery * BooleanQuery也是实际开发过程中经常使用的一种Query. * 它其实是一个组合的Query,在使用时可以把各种Query对象添 ...

  2. 向DataGrid数据表格增加查询搜索框

    向DataGrid数据表格增加查询搜索框 效果如下: js代码: $(function(){ var dg = $('#dg').datagrid({ url:"${pageContext. ...

  3. Lucene.net 多条件查询搜索

    最近一直在研究lucene,目的是想让网站实现像搜索引擎那样的搜索,可以快速.准确的帮用户查询出想要的结果.废话不多说,上代码实例: 1.利用BooleanQuery进行多条件搜索(比较灵活)   L ...

  4. yii Query Builder (yii 查询构造器) 官方指南翻译

    /**** Query Builder translated by php攻城师 http://blog.csdn.net/phpgcs Preparing Query Builder 准备 Quer ...

  5. NSPredicate 查询/搜索

    IOS NSPredicate 查询.搜索   简述:Cocoa框架中的NSPredicate用于查询,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取. 最常用到的函数 + (NSP ...

  6. Linux就该这么学--命令集合6(打包压缩文件、文件查询搜索命令)

    1.tar命令用于对文件打包压缩或解压:(tar [选项] [文件]) 打包并压缩文件:tar -czvf 压缩包名.tar.gz 文件名 解压并展开压缩包:tar -xzvf 压缩包名.tar.gz ...

  7. yii 查询垃圾分类接口

    public function actionGarbage() { // $param = \Yii::$app->request->post('rubbish', ''); // 接收j ...

  8. 使用.NET 6开发TodoList应用(15)——实现查询搜索

    系列导航及源代码 使用.NET 6开发TodoList应用文章索引 需求 本文我们继续来看查询过程中的另外一个需求:搜索.搜索的含义是目标字段的全部或者部分值匹配请求中的搜索条件,对应到数据库层面是C ...

  9. Symfony3 查询搜索功能DQL语句like查询

    //前台页面代码 <form method="GET" action="{{ path('staff_index') }}" name="sea ...

随机推荐

  1. WEB网页专业词汇 汇总

    Accessibility  可访问性 accessor properties 存取器属性 addition 加法 aggregate 聚合 alphabetical order 字母表顺序 Anch ...

  2. linux下从源代码安装git的问题(install from source)

    安装环境:centos7.2 安装依赖包: yum install -y gcc .el7..x86_64 openssl-devel.x86_64 yum install -y curl.x86_6 ...

  3. openpyxl之excel操作

    一.读取excel中内容 1.导入模块 : from openpyxl import load_workbook 2.打开excel : workbook = load_workbook(" ...

  4. 主攻ASP.NET MVC4.0之重生:CheckBoxListHelper和RadioBoxListHelper的使用

    在项目中新建Helpers文件夹,创建CheckBoxListHelper和RadioBoxListHelper类. CheckBoxListHelper代码 using System; using ...

  5. mongodb count 导致不正确的数量(mongodb count 一个坑)

    在mongodb 集群中,if  存在orphaned documents 和chunk migration, count查询可能会导致一个不正确的查询结果,例如我就是踩的这个坑,先不说话,看结果: ...

  6. HTML5 JS 压缩图片,并取得图片的BASE64编码上传

    基本过程 1) 调用 FileReader 的 reader.readAsDataURL(img); 方法, 在其onload事件中, 将用户选择的图片读入 Image对象. 2) 在image对象的 ...

  7. poj 1679 The Unique MST 【次小生成树+100的小数据量】

    题目地址:http://poj.org/problem?id=1679 2 3 3 1 2 1 2 3 2 3 1 3 4 4 1 2 2 2 3 2 3 4 2 4 1 2 Sample Outpu ...

  8. CDN技术介绍

    CDN技术介绍 一.CDN概述 1.1 CDN定义 CDN即Content Delivery Network (内容分发网络).CDN是建立在现有IP网络基础结构之上的一种增值网络.是在应用层部署的一 ...

  9. Centos6.5安装Mysql5.6.10

    1. 先卸载掉老版本的mysql(linux严格区分大小写,查找的时候加上-i参数,和mysql相关的全部要卸) [root@liuchao ~]# rpm -qa | grep -i mysqlMy ...

  10. 【P2629】好消息,坏消息(前缀和+单调队列优化DP)

    一激动一颓就会忘了总结... 前面的大黄题就不总结了. 这个题我只想说一声艹,一开始的思路就是正确的,然后计算的时候有了一个瑕疵,不过很快也就改过来了.然后却一直连样例都过不了.仔仔细细看了老半天,经 ...