This article mainly introduces the method of finding database of the criteria of YII model operation, analyzes the examples of criteria in Yii model and the related skills of query operation, and the need of friends can refer to
This paper describes the method of finding a database for the criteria of YII model operation. Share to everyone for your reference, as follows:
Data Model Search methods:
Public Function Search () { //Warning:please Modify the following code to remove attributes that //should not being Searched. $criteria =new Cdbcriteria; $criteria->compare (' id ', $this->id); $criteria->compare (' title ', $this->title,true); Support Fuzzy Lookup $criteria->compare (' content ', $this->content,true)//Support Fuzzy Lookup $criteria->compare (' type ') , $this->type); $criteria->compare (' user ', $this->user,true); Support Fuzzy Lookup $criteria->compare (' status ', $this->status); $criteria->compare (' Create_data ', $this->create_data,true); Support for Fuzzy Lookup return new Cactivedataprovider ($this, Array ( ' criteria ' = $criteria, ' pagination ' = Array ( ' pageSize ' =>50, ),) );}
To define a comparison operation:
$criteria->compare (' create_time ', ' <= '. $this->endtime),//create morning less than equals specified time
Define the fields you want to find:
Find results $criteria->select = ' id,title,content,author,status,createtime ',//can also be defined in one of the following ways $criteria->select = Array (' ID ', ' title ', ' content ', ' author ', ' Status ', ' Createtime '),
Define fill-In search criteria:
Define Condition $criteria->select = ' Status=1 ',//Add match $criteria->compare (' title ', $this->title,true),//Add condition $ Condition can be an array, or it can be a string, and can omit $criteria->addcondition ($condition, ' and '),//Add the in Condition $column as the field name $criteria-> Addincondition (string $column, array $values, string $operator = ' and ')//Add Notin condition $criteria->addnotincondition ( String $column, array $values, string $operator = ' and ')//Add Like Condition $criteria->addsearchcondition (string $column, String $keyword),//Add between Condition $criteria->addbetweencondition (string $column, String $valueStart, String $valueEnd , String $operator = ' and '),
Join Table Query
$criteria->join = ' Left join users on Users.id=authorid ',
Order Query Result Sort:
$criteria->order = ' Createtime DESC ',
Group result groupings:
$criteria->group = ' ProjectID, Teamid ',
Having a filtered grouping result group number:
$criteria->having = ' SUM (revenue) <50000 ',
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!