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!

  • 相关阅读:
    班课2
    班课2
    班课1
    lecture 2
    lecture 1
    使用node的fs读取文件
    使用Node.js搭建一个本地服务器
    Node.js前言
    简述ES6其他的东西
    ES6异步操作Thunk、co和async
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/2050850.html
Copyright © 2011-2022 走看看