• [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!

  • 相关阅读:
    Mac 如何让python默认运行python3.8
    python发送post请求(转)
    Qt 学习(4)
    自定义Qt组件-通讯模块(P3)
    自定义Qt组件-通讯模块(P2)
    自定义Qt组件-通讯模块(P1)
    用 JS 做一个数独游戏(二)
    用 JS 做一个数独游戏(一)
    公交车情况数问题
    传球问题
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/2050850.html
Copyright © 2020-2023  润新知