Yii cgridview dataprovider错误

时间:2014-01-01 01:39:21

标签: php yii

我有2个型号vseq和rseq。我试图在vseq视图上使用rseq sql语句中的数据提供者。当我将cgridview放在vseq页面上时,页面变为空白但不会给我任何特定的错误。当我把它从页面上取下来呈现时很好。

以下是我的Rseq模型中的代码:

public function getReceipts($patno){
$sql = " SELECT rseq.rdate AS receiptDate, rseq.ramount AS receiptAmount, rseq.rtype AS     receiptType, rseq.rcomment AS receiptComment
             FROM  rseq
             INNER JOIN vseq 
             ON rseq.rno = $patno
             LIMIT 500
    ";

    $connection=Yii::app()->db;
    $command=$connection->createCommand($sql);
    $dataReader=$command->query(); 
    $result=$dataReader->readAll();

    return $result;
}

以下是我的Vseq视图中的代码:

$vpatNo = Vseq::model()->getPatient($vseqNo);
$test = $vpatNo['0']['vnum'];

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'rseq-grid',
'dataProvider'=>Rseq::model()->getReceipts($test),
//'filter'=>$model,
'columns'=>array(
    //'ID',
    //'vlinevnum',
    //'vlinelineno',
    //'vlinefromdate',
    'receiptDate',
    array(
        'class'=>'CButtonColumn',
    ),
),
));

是否有我遗漏的东西,我似乎无法找出这些数据提供者。

1 个答案:

答案 0 :(得分:0)

必须使用CArrayDataProvider

在Rseq模型中:

public function getReceipts($patno){
    $sql = " SELECT rseq.rdate AS receiptDate, rseq.ramount AS receiptAmount, rseq.rtype AS     receiptType, rseq.rcomment AS receiptComment
             FROM  rseq
             INNER JOIN vseq 
             ON rseq.rno = $patno
             LIMIT 500
    ";

    $resultAll =Yii::app()->db->createCommand($sql)->queryAll();
    return new CArrayDataProvider($resultAll);
}