The GII generates the following:
<?= detailview::widget ([ $model, ' attributes ' = [ ' id ', [ ' label ' = ' name ', ' value ' = '$model->name] , '?>
The customizations are as follows:
<?= detailview::widget ([ ' model ' = [ ' id ', ' label ' = ' name ', ' value ' => $model ->name)],] , ' template ' = ' <tr><th>{label}</th><td>{value}</td></tr> ', ' O ptions ' = = [' Class ' = ' table table-striped table-bordered detail-view '],?
the HTML after the output is : Class= "Table table-striped table-bordered Detail-view" ><tr><th>uid</th><td>1 </td></tr><tr><th>gender</th><td>female</td></tr></table > Other specific parameters, refer to "[Yii\widgets\detailview] (https://github.com/yiisoft/yii2/blob/master/ framework/widgets/detailview.php) "
Public $attributes;/** * @var string|callable the template used to render a single attribute. If A string, the token ' {label} ' * and ' {value} ' is replaced with the label and the value of the corresponding attrib Ute. * If a callback (e.g. an anonymous function), the signature must is as follows: * * ~ ~ ~ function ($attribute, $index, $w Idget) * ~ ~ ~ * where ' $attribute ' refer to the specification of the attribute being rendered, ' $index ' is the zero-based * Index of the attribute in the [[Attributes]] array, and ' $widget ' refers to this widget instance. */ Public $template= "<tr><th>{label}</th><td>{value}</td></tr>";/** * @var array The HTML attributes for the container tag's this widget. The "tag" option specifies * what container tag should is used. It defaults to the "table" if not set. * @see \yii\helpers\html::rendertagattributes () for details on how attributes is being rendered. */ Public $options= [' class ' = ' table table-striped table-bordered detail-view '];/** * @var array| Formatter the Formatter used to format model attribute values into displayable texts. * This can is either an instance of [[[Formatter]] or a configuration array for creating the [[Formatter]] * instance. If The property was not set, the "formatter" application component would be used. */ Public $formatter;
$options can freely define, such as:<?= DetailView::Widget ([' Model ' =$model, ' attributes ' = [ ' UID ', [' Label ' = ' gender ', ' value ' =$model->getgendertext ()], ], ' template ' = ' <tr><th>{label}</th><td>{value}</td></tr> ', ' options ' = [' class1 ' = ' table table-striped table-bordered Detail-view '],]) ?>defined as Class1, the output HTML is:<table class1= "Table table-striped table-bordered Detail-view" ><tr><th>uid</th><td>1 </td></tr><tr><th>gender</th><td>female</td></tr></table >
This digest from: http://www.yiichina.com/question/418
yii2.0 DetailView Custom Styles