How to create a custom ActionColumn in the gridView of yii2?

后端 未结 2 1240
甜味超标
甜味超标 2021-02-05 19:25

I have a gridView and i managed to get it to contain the data i need, but what i need to do next is to create a column which contains two buttons for has_facebook and has_twitte

2条回答
  •  感动是毒
    2021-02-05 20:04

    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 '
    '.$model->id.' and other html-code
    '; }, ],

    This function

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

    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.

提交回复
热议问题