Known
Modelname::model ()-> find ()//Finding an Object
Modelname::model ()-> findall ()///Find an array of object collections
How to find the data for the fields I need, not the data for all the fields
That's what I did before.
$criteria = new Cdbcriteria;
$criteria->select = ' username,id,email ';
$criteria->order = ' id DESC ';
$users = Modelname::model ()->findall ($criteria);
Backstage accidentally see others have so written, find themselves how ignorant
$users = Modelname::model ()->findall (Array ('
select ' =>array (' username ', ' id ', ' email '),
' order ' => ' ID DESC ',
));
After the test found that can be used, then find can also operate this
$user = Modelname::model ()->find (Array ('
select ' =>array (' username ', ' id ', ' email '),
' order ' => ' ID DESC ',
' condition ' => ' id= '. $id,
));
Of course, it's certainly not safe to do this, and replace it with the following method
$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 '),
));
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 time or the need for the new below Cdbcriteria
For example, I want to remove the ' v_id ', ' title ', ' Big_class ', ' sub_class ', ' upload_time ', ' comment_num ', and so on in the Videoinfo table, and the conditions are Status=1, Follow LastModifyTime in reverse order, and only 3 can be removed to do so:
$criteria = new Cdbcriteria ();
$criteria-> select = Array (' v_id ', ' title ', ' Big_class ', ' sub_class ', ' upload_time ', ' comment_num ');
$criteria-> condition = ' status = 1 ';
$criteria-> order = ' lastmodifytime desc ';
$criteria-> limit = 3;
$criteria->params = Array (': Status ' => $ your variable);
One of the lines I commented out is a variable, with a placeholder, for example, if your status needs to be assigned according to the variable, you can assign a value to the line in the annotation, and then write the condition condition
$criteria-> condition = ' status ': status ';
Can
So, the result you get when you $result a variable, it's a list of objects that you need to traverse:
foreach ($result as $ob) {
print_r ($ob->attributes);
Like you want to show each field just by typing
Wait, you can.
Cpagination class can be used with the Cdbcriteria class and the front page plugin to support paging:
$count =videoinfo::model ()->count ($criteria)
$pages =new cpagination ($count);
$pages->pagesize=30; How many
$pages->applylimit per page ($criteria);
$result = Videoinfo::model ()->findall ($criteria);