12

gridView があり、必要なデータを含めることができましたが、次に行う必要があるのは、has_facebook と has_twitter の 2 つのボタンを含む列を作成することです。

<?=
 GridView::widget([
     'dataProvider'=>$dataProvider,
     'filterModel' =>$searchModel,
     'columns'     =>[
         ['class'=>'yii\grid\SerialColumn'],
         'name',
         'cm_name',
         'has_facebook',
         'has_twitter',             
         ['class'=>'yii\grid\ActionColumn'],
     ],
 ]);
?>

名前 | cm_name | プラットフォーム

アカウント1 | ジャック | ボタン1 ボタン2

ここで、btn1 と btn2 は facebook と twitter を指します。

テーブル汚くてすみません。

4

2 に答える 2

29

You don't need to create own column Class. You can create simple raw-column and show there anything you want:

[
    'attribute' => 'some_title',
    'format' => 'raw',
    'value' => function ($model) {                      
            return '<div>'.$model->id.' and other html-code</div>';
    },
],

This function

function ($model) {                      
    return '<div>'.$model->id.' and other html-code</div>';
}

names callback function. There is core method evaluateExpression in CComponent:

public function evaluateExpression($_expression_,$_data_=array())
{
    if(is_string($_expression_))
    {
        extract($_data_);
        return eval('return '.$_expression_.';');
    }
    else
    {
        $_data_[]=$this;
        return call_user_func_array($_expression_, $_data_);
    }
}

in our case expression is not string, it's a function, so it runs php method call_user_func_array and pass into it your model.

于 2014-04-28T18:10:11.173 に答える