Yii: how to find the specified fields in findfindAll, yiifindall_PHP tutorial

Source: Internet
Author: User
Yii method for finding the specified field in findfindAll, yiifindall. Yii describes how to use findfindAll to find the specified field. yiifindall finds an object modelName: model ()-find (): modelName: model ()-findALL () find the Yii method for finding findAll to find the specified field, yiifindall

General Office

ModelName: model ()-> find () // identifies an object modelName: model ()-> findALL () // identifies an array of an object set

How can I find out the data of all fields instead of the data of all fields?

I did this before.

$criteria = new CDbCriteria;$criteria->select = 'username,id,email';$criteria->order = 'id DESC';$users = modelName::model()->findAll( $criteria );

The background accidentally saw what others wrote and how ignorant they were.

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

After the test, it is found that it can be used, so find can also perform this operation.

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

Of course, it is definitely not safe to do so. the method below is the same.

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

Similarly, you can use findAll to test it. conclusion:

This method can easily obtain the required data. of course, the following 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 writing

Write as follows:
$ Db = new CDbCriteria ();
$ Db-> addInCondition ('id', array (1, 2, 3 ));
$ Newstypelist = NewsType: model ()-> findAll ($ db );

Http://www.bkjia.com/PHPjc/874529.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/874529.htmlTechArticleYii about find findAll find out the method of the field, yiifindall Total named modelName: model ()-find () // find out is an object modelName: model () -findALL () // find...

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.