DetailView内匿名函数不可用

DetailView

yiiwidgetsDetailView 小部件显示的是单一 yiiwidgetsDetailView::$model 数据的详情。

它非常适合用常规格式显示一个模型(例如在一个表格的一行中显示模型的每个属性)。 这里说的模型可以是 yiiaseModel 或者其子类的一个实例,例如子类 active record,也可以是一个关联数组。

DetailView使用 yiiwidgetsDetailView::$attributes 属性来决定显示模型哪些属性以及如何格式化。 可用的格式化选项,见 formatter section 章节。

一个典型的DetailView的使用方法如下:

echo DetailView::widget([
    'model' => $model,
    'attributes' => [
        'title',               // title attribute (in plain text)
        'description:html',    // description attribute formatted as HTML
        [                      // the owner name of the model
            'label' => 'Owner',
            'value' => $model->owner->name,
        ],
        'created_at:datetime', // creation date formatted as datetime
    ],
]);
原文地址:https://www.cnblogs.com/jerrypro/p/6413252.html