nettrinity
(Thanhvn Info)
October 22, 2011, 7:34pm
1
The result of CDbCommand is a CDbDataReader instance. The reason I don’t plan to use AR is because AR is 3 times slower than DAO ( and CDbCommand ). I just learned this info from the test result in Yii 1.1 Application Development Cookbook. Is this true?
If I don’t use AR (CActiveDataProvider), how to pass the data to the display widget such as CListview?
Thanks!
putera
(Libputera)
October 22, 2011, 7:52pm
2
nettrinity:
The result of CDbCommand is a CDbDataReader instance. The reason I don’t plan to use AR is because AR is 3 times slower than DAO ( and CDbCommand ). I just learned this info from the test result in Yii 1.1 Application Development Cookbook. Is this true?
If I don’t use AR (CActiveDataProvider), how to pass the data to the display widget such as CListview?
Thanks!
You can use one of the following that implement IDataProvider: CArrayDataProvider, CDataProvider, CSqlDataProvider.
pavspavi88
(Pavspavi88)
October 25, 2011, 2:21pm
4
Can I know how you were successful in implementing the above said?
nettrinity
(Thanhvn Info)
October 25, 2011, 3:38pm
5
Yes, it works.
This is my view code:
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_SearchResultItem' // refers to the partial view named '_SearchResultItem'
));
//CVarDumper::dump($dataProvider);
?>
This is the code to generate CArrayDataProvider
$dataProvider=new CArrayDataProvider($rawData->readAll(), array(
'id'=>'test1111',
'pagination'=>array('pageSize'=>10),
'sort'=>array(
'attributes'=>array(
'id', 'name'))
));
This is the code to get query result, but it’s not an array. You need to call readAll() to convert it to an array
$rawData = Yii::app()->db->createCommand()
->select()
->from('company')
->where('vid=:vid', array(':vid'=>$keyWord))
->query();
Does it help?