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