yii2 detailview设置值与函数htmlspecialchars()期望参数1是字符串,给定对象

时间:2015-09-01 08:32:25

标签: yii2 yii2-advanced-app yii2-basic-app

如何设置DetailView的值。我正在尝试设置值gridview,但这只是显示错误结果

这是我写的代码

<?php echo  DetailView::widget([
    'model' => $model,
    'attributes' => [
        'username',
        'email',
        [   'label' => 'Nama',
            'value' => function($model) { return $model->first_name ." ". $model->last_name; },
        ],
    ],
]); ?>

错误是:

htmlspecialchars() expects parameter 1 to be string, object given

1 个答案:

答案 0 :(得分:2)

DetailView中,无需在function属性中使用value

  <?php echo  DetailView::widget([
    'model' => $model,
    'attributes' => [
        'username',
        'email',
        [   'label' => 'Name',
            'value' => $model->first_name ." ". $model->last_name,
        ],
    ],
  ]); ?>