http://sonsonz.wordpress.com/2011/10/14/yii-examples-of-using-cdbcriteria/
Examples of Using CDbCriteria
Basic Usage
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Products = Product::model()->findAll($Criteria);
OR
//An example using the constructor to populate the properties.
$Criteria = new CDbCriteria(array('condition' => 'price > 30'));
$Products = Product::model()->findAll($Criteria);
Personally, I like to go with the first approach. I think it’s generally easier to read, but that’s just my personal preference.
Adding A Limit
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Products = Product::model()->findAll($Criteria);
Limit with Offset
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Criteria->offset = 1;
$Products = Product::model()->findAll($Criteria);
Ordering Results
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Criteria->offset = 1;
$Criteria->order = "name ASC";
$Products = Product::model()->findAll($Criteria);
Limiting Selected Fields
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Criteria->limit = 1;
$Criteria->offset = 1;
$Criteria->order = "name ASC";
$Criteria->select = "id, name";
$Products = Product::model()->findAll($Criteria);
Example relation with :
$criteria = new CDbCriteria;
$criteria->with = array('foreign_table1',
'foreign_table2',
'foreign_table2.foreign_table3');
$criteria->together = true; // ADDED THIS
$criteria->select = array('id');
$criteria->condition = "foreign_table1.col1=:col_val AND
foreign_table3.col3=:col_val2";
$criteria->params = array(':col_val' => some_val, ':col_val2' => other_val);
$criteria->order = 'foreign_table3.col5 DESC';
$criteria->limit = 10;
分享到:
相关推荐
主要介绍了Yii的CDbCriteria查询条件用法,实例总结了CDbCriteria查询条件的常见用法,对于使用Yii进行数据库程序设计具有一定的参考借鉴价值,需要的朋友可以参考下
我最近接触yii总结的一点经验,希望能帮助大家
本文实例讲述了Yii CDBCriteria常用方法。分享给大家供大家参考,具体如下: 注:$c = new CDbCriteria();是ActiveRecord的一种写法,使ActiveRecord更加灵活,而不是手册中DAO(PDO)和Query Builder。 小小点评...
很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架很好用yii框架
to becoming a master of Yii. From initialization and configuration to debugging and deployment, this book will be your guide to becoming a master of all aspects of this powerful framework.
You will learn about taking shortcuts using core features, creating your own reusable code base, using test driven development, and many more topics that will give you a lot of experience in a ...
"The Yii Book: Developing Web Applications Using the Yii PHP Framework" written by Larry Ullman and published over the course of 2012 and 2013. This book, and the selling of it, is a bit of an ...
Yii2.0级基于Yii1.X完全重写的,不仅是小版本升级的升级。所以想要系统学习Yii2.0这个框架这套教程可以从实战项目带你入手。不错的学习YII框架的基础课程,电商系统的结构完整、框架资源太大,传百度网盘了,链接在...
Learning Yii Testing embraces a testing-first strategy to guide you in the implementation of all possible types of tests, covering the core features of Yii 2. Starting with the nuts and bolts of ...
《深入理解Yii2.0》是一本干货。主要讲解Yii2.0及所代表的最新一代Web开发框架的新特性、新技术、新理念、新模式。 采用的方式是分析框架的源代码,尝试从根上进行理解和阐述,并融入个人使用Yii开发的一些经验和...
Yii采用严格的OOP编写,并有着完善的库引用以及全面的教程。从 MVC,DAO/ActiveRecord,widgets,caching,等级式RBAC,Web服务,到主题化,I18N和L10N,Yii提供了今日Web 2.0应用开发所需要的几乎一切功能。事实上...
Understand the difference between the Yii 1.x.x versions using useful examples from real web applications Book Description Yii is a free, open source web application development framework written in ...
yii1.1.10 开发包(包含yii权威指南以及yii博客例子讲解)
Yii权威指南思维导图 yii类结构 类导图 权威指南
Yii 是什么 Yii 是一个基于组件、用于开发大型 Web 应用的高性能 PHP 框架。它将 Web 编程中的可重用性发挥到极致,能够显著加速开发进程。Yii(读作“易”)代表简单(easy)、高效(efficient)、可扩展(extensible)。...
yii框架中文手册教程和YII模板 我很辛苦才找到的
Yii2参考手册,Yii2中文手册完整版
YII 多种缓存机制的运用 如文件缓存内存缓存 动态缓存等