When we using CGridView in Yii, we may want to a link as a column. So in common sense, we will use CLinkColumn to do that, as these code:

<?php $this->widget('zii.widgets.grid.CGridView', array(
    
'dataProvider'=>$dataProvider,
    
'columns'=>array(
        
array(
            
'name'=>'username',
            
'class'=>'CLinkColumn',
            
'labelExpression'=>'$data->username',
            
'urlExpression'=>'Yii::app()->createUrl("admin/user", array("id"=>$data->id))',
        )
,
    )
,

)); ?> 

 

But we can not sort the username with this way. Thanks for Yii, we can use another way to do it. Here are the code:

<?php $this->widget('zii.widgets.grid.CGridView', array(
    
'dataProvider'=>$dataProvider,
    
'columns'=>array(
        
array(
            
'name' => 'username',
            
'type' => 'raw',
            
'value' => 'CHtml::link($data->username,Yii::app()->createUrl("admin/user/view", array("id"=>$data->id)))'
        )
,
    )
,

)); ?>  

Have fun with Yii!

相关文章:

  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2022-01-02
  • 2022-12-23
  • 2021-07-19
猜你喜欢
  • 2021-12-10
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2021-09-16
  • 2021-11-09
  • 2022-01-13
相关资源
相似解决方案