Yii2 view 层显示值

1). Yii2 view 层显示值

[
    'attribute'=>'字段名',
    'format' => 'raw',
    'value'=> call_user_func(function ($model){
        $img_url = "图片路径";
        return Html::a(
            Html::img($img_url,
            ['style'=>'height:100px;height:80px']),
            $img_url,
            ['target'=>'_blank']);
    },$model)
];

2).数据转换, 时间戳格式化; 官方参考地址

class Customer extends ActiveRecord
{
    // ...

    public function getBirthdayText()
    {
        return date('Y/m/d', $this->birthday);
    }
    
    public function setBirthdayText($value)
    {
        $this->birthday = strtotime($value);
    }
}

// 现在可以使用 $customer->birthdayText; 而不是 $customer->birthday

3)   Yii2 view 层显示值02

[
    'class' => 'yiigridActionColumn',
    'header' => '操作',
    'template' => '{view} {update} {delete}',
],

其他: https://packagist.org/packages/yiithings/yii2-softdelete

原文地址:https://www.cnblogs.com/dafei4/p/12939198.html