Yii about Find FindAll finding out the method of the developed field, yiifindall_php tutorial

Source: Internet
Author: User

Yii about Find FindAll finds out the method of the field that was developed, Yiifindall


Always known

// to find out is an object Modelname::model (), FindALL () // Find an array of object collections

How to find the data for the fields I need, not all of the fields

That's what I did before.

$criteria New Cdbcriteria; $criteria->select = ' username,id,email '; $criteria->order = ' id DESC '; $users $criteria );

Backstage to see others have so written, found that they are how ignorant

$users = Modelname::model ()->findall (array(    ' select ' = =array (' username ', ' id ', ' email '),    ' order ' = ' id DESC ', ') ;

After the test, I found that it can be used, so find can do the same.

$user = Modelname::model ()->find (array(    ' select ' = =array(' username ') , ' id ', ' email '),    ' order ' = ' id DESC ',    ' condition ' = ' id= '. $id,));

Of course, it's not safe to do this, but it's also possible to change to the following method

$users $this->user->find (array(    ' select ' = =array(' id ', ' Username ', ' email '),    ' order ' = ' id DESC ',    ' condition ' = ' state=:state and Id=:id ',    array (': state ' = ' 1 ', ': id ' = ' 2 '),));

It's also possible to use the FindAll test, the conclusion

This method can be very convenient to obtain the required data, of course, the need for paging or new Cdbcriteria


Yii Framework, $retrievedProject =project::model ()->findall (); How to Output?

$retrievedProject =project::model ()->findall ();
foreach ($retrievedProject as $v) {
echo $v->attributes[' title '];
}

Yii Query Statement notation

Write this:
$db = new Cdbcriteria ();
$db->addincondition (' id ', array (+/-));
$newstypelist =newstype::model ()->findall ($DB);

http://www.bkjia.com/PHPjc/874529.html www.bkjia.com true http://www.bkjia.com/PHPjc/874529.html techarticle Yii about Find FindAll method of finding out the fields that are developed, Yiifindall is known Modelname::model ()-Find ()//Find an Object Modelname::model ()-FindAll () Find out the ...

  • 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.