Find a Database Method __ Database

Source: Internet
Author: User
Tags yii
yii-Model-Criteria Lookup database methodCriteri find Yii Search method yii lookup Yii Lookup Database

Data Model Search methods:[HTML] View Plain copy print? Public function search ()    {       // Warning:  please modify the following code to remove attributes that       // should not be searched.            $criteria =new cdbcriteria;           $criteria-> Compare (' id ', $this->id);        $criteria->compare (' title ', $this->title, true);                 //supports Fuzzy Lookup         $criteria->compare (' content ', $this->content,true);             //support for Fuzzy Lookup         $criteria- >compare (' type ', $this->type);        $criteria->compare (' user ', $This->user,true);               // Support for 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,            ),       );  }  


Define comparison operations [HTML] view plain copy print? $criteria->compare (' create_time ', ' <= '. $this->endtime),//creation morning is less than or equal to the specified time

Define the field to find [HTML] view plain copy print? The result of the lookup $criteria->select = ' id,title,content,author,status,createtime ',//can also be defined in one of the following ways $criteria->select = AR Ray (' id ', ' title ', ' content ', ' author ', ' Status ', ' Createtime '),

Define fill in Find conditions [HTML] view plain copy print?//define Conditions      $criteria->select =    ' Status=1 ',  //Add match    $criteria->compare (' title ', $this->title,true),   //Add condition   $condition can be an array or a string, and can omit    $criteria->addcondition ($condition, ' and ' ,  //Add in Condition   $column for 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 [HTML] view plain copy print? $criteria->join = ' Left join users on Users.id=authorid ',

Order query result sort [HTML] view plain copy print? $criteria->order = ' Createtime DESC ',

Group result grouping [HTML] view plain copy print? $criteria->group = ' ProjectID, Teamid ',

Having filtered group result grouping quantity [HTML] view plain copy print? $criteria->having = ' SUM (revenue) <50000 ',

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.