A method to find the criteria in the operation of YII model

Source: Internet
Author: User
Tags yii
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.