Hi there,
I wanted to use code generated by Gii for displaying all results of a particular model (slightly modified by me, but still working without any problems):
$criteria = new CDbCriteria;
$criteria->select='ID, LOGN, MAIL';
$dataProvider = new CActiveDataProvider($model, array
(
'pagination'=>array('pageSize'=>20),
'sort'=>array('defaultOrder'=>'ID'),
'criteria'=>$criteria,
));
$this->widget('zii.widgets.grid.CGridView', array
(
'id'=>'users-grid',
'dataProvider'=>$dataProvider,
'filter'=>$model,
'columns'=>array
(
'ID',
'LOGN',
'MAIL',
array
(
'class'=>'CButtonColumn',
),
),));
and to change it from using CActiveDataProvider to CSqlDataProvider. Therefore I pasted example code found in CSqlDataProvider in class reference with a little bit modifications from my side:
$count = Yii::app()->db->createCommand('SELECT COUNT(*) FROM WWW_USERS')->queryScalar();
$sql = 'SELECT * FROM WWW_USERS';
$dataProvider = new CSqlDataProvider($sql, array
(
'id'=>'user',
'keyField'=>'ID',
'totalItemCount'=>$count,
'sort'=>array
(
'attributes'=>array
(
'ID', 'LOGN', 'MAIL',
),
'defaultOrder'=>'ID'
),
'pagination'=>array
(
'pageSize'=>20,
),
));
But I have to turn-off (comment-out) CButtonColumn column because with it enabled (first block of code) I’m getting error: “Trying to get property of non-object” with “CComponent.php(616) : eval()'d code:1”.
Since in both cases I used not my own code (first generated by Gii, second taken from guide), if I didn’t broke something during these slight customizations, then it seems to be an internal, core-code related problem. And I started this thread to ask, if someone has similar problems or maybe if someone sees an error in the code, I can’t find. Thank you.