zoukankan      html  css  js  c++  java
  • [Yii Framework] Add a link in CGridView

    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!

  • 相关阅读:
    HDU 5744
    HDU 5815
    POJ 1269
    HDU 5742
    HDU 4609
    fzu 1150 Farmer Bill's Problem
    fzu 1002 HangOver
    fzu 1001 Duplicate Pair
    fzu 1150 Farmer Bill's Problem
    fzu 1182 Argus 优先队列
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/2050850.html
Copyright © 2011-2022 走看看