当dataProvider与CSqlDataProvider一起使用时,Yii-CGridView列链接是否有效?

时间:2012-09-19 07:13:46

标签: yii

我在CGridView中使用的代码在列值中的$ data-&gt; gen_id和$ data-&gt; erc_gen中给出了一个空值,当我用浏览器检查器检查时它给了我<a href="/ekportal/erc/index.php?r=ercGen/update&amp;id="></a>

下面的ercgen / admin代码:

$qryTmp = 
    "SELECT gen_id, erc_ref,B.complete_name sales_executive,C.description type,D.client_name client_id,event_name, E.status_desc erc_status ".
    "FROM erc_gen A, Users B, erc_type C, clients D, erc_status E ".
    "WHERE A.sales_executive = b.user_id ".
    "AND A.type = C.typ_no ".
    "AND A.client_id = D.client_id ".
    "AND A.erc_status = E.id ".
    "AND sales_executive = '$user_id' ".
    "AND erc_status = '1' ";
$count = Yii::app()->db->createCommand('SELECT COUNT(*) FROM ('.$qryTmp.') X')->queryScalar();
$dataProvider=new CSqlDataProvider($qryTmp, array(
'totalItemCount'=>$count,
'sort'=>array(
    'attributes'=>array(
         'gen_id','erc_ref', 'sales_executive', 'type','client_id','event_name','erc_status'
    ),
),
'pagination'=>array(
    'pageSize'=>10,
),
));

//CGRIDVIEW
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'pager'=>array(
    'header'=>'',
    'firstPageLabel'=>'&lt;&lt;',
    'prevPageLabel'=>'&lt;',
    'nextPageLabel'=>'&gt;',
    'lastPageLabel'=>'&gt;&gt;',
),   
'columns'=>array(
    array(
        'header'=>'#',
        'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
    ),
    array(
        'header'=>'Reference Number',
        'name'=>'erc_ref',
        'type'=>'raw',
        'value'=>'CHtml::link($data->erc_ref,Yii::app()->createUrl("ercGen/update",array("id"=>"$data->gen_id")))',
    ),

1 个答案:

答案 0 :(得分:3)

我找到了答案here

只需将$data->erc_ref更改为$data['erc_ref'],将$data->gen_id更改为$data['gen_id']