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 );