GII 生成如下:

<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
['label'=>'name','value'=>$model->name],
],
]) ?>

自定义如下:

<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
['label'=>'name','value'=>$model->name)],
],
'template' => '<tr><th>{label}</th><td>{value}</td></tr>',
'options' => ['class' => 'table table-striped table-bordered detail-view'],
]) ?>
输出后的HTML为:

    <table 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>

其它具体参数,可以参考【[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}` will be replaced with the label and the value of the corresponding attribute.
* If a callback (e.g. an anonymous function), the signature must be as follows:
*
* ~~~
* function ($attribute, $index, $widget)
* ~~~
*
* 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 of this widget. The "tag" option specifies
* what container tag should be used. It defaults to "table" if not set.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are 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 be either an instance of [[Formatter]] or an configuration array for creating the [[Formatter]]
* instance. If this property is not set, the "formatter" application component will be used.
*/
public $formatter;
$options可以自由定义,比如:

<?= 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'],
]) ?> 定义为class1,输出的HTML为:
<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>

本文摘自:http://www.yiichina.com/question/418

yii2.0 DetailView 自定义样式的更多相关文章

  1. yii2.0保留CSS样式的引入

    <link rel="stylesheet" href="http://cdn.staticfile.org/twitter-bootstrap/3.2.0/css ...

  2. 7.Yii2.0框架自定义全局工具函数

    功能: 新建共用方法的打印方法,可以很方便的格式化打印 一.新建helper/function.php <?php /** * Created by Haima. * Author:Haima ...

  3. yii2.0 如何按需加载并管理CSS样式及JS脚本

    链接:http://www.yiichina.com/tutorial/399 (注:以下为Yii2.0高级应用测试) Yii2.0对于CSS/JS 管理,使用AssetBundle资源包类. 视图如 ...

  4. Yii2 ActiveForm表单自定义样式

    实例: <?php $form = ActiveForm::begin([ 'fieldConfig' => [ 'template' => '<div class=" ...

  5. 教你在Yii2.0框架中如何创建自定义小部件

    本教程将帮助您创建自己的自定义小部件在 yii framework 2.0.部件是可重用的模块和用于视图. 创建一个小部件,需要继承 yii\base\Widget,覆盖重写 yii\base\Wid ...

  6. yii2.0下拉列表的使用

    第一种方法:ActiveForm 类的 dropDownList 方法(优点,默认使用yii的样式) 1.在控制器的方法里面 ,我们需要拿到数据,一定是 findAll() 或者是 all() 方法的 ...

  7. 一步步开发自己的博客 .NET版 剧终篇(6、响应式布局 和 自定义样式)

    前言 这次开发的博客主要功能或特点:    第一:可以兼容各终端,特别是手机端.    第二:到时会用到大量html5,炫啊.    第三:导入博客园的精华文章,并做分类.(不要封我)    第四:做 ...

  8. Android RatingBar 自定义样式

    Android RatingBar 自定义样式 1.先定义Style: <style name="RadingStyle" parent="@android:sty ...

  9. 自定义样式RatingBar的使用

    1.设置布局文件,自定义ratingbar样式 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an ...

随机推荐

  1. NSPredicate,谓词

    原文地址:http://blog.csdn.net/holydancer/article/details/7380799 在语言上,谓语,谓词是用来判断的,比如“我是程序猿”中的是,就是表判断的谓语, ...

  2. bat操作数据库mysql

    createDB.bat文件内容: @echo off cd C:/Program Files/cl_ZWL_App/<a href="http://lib.csdn.net/base ...

  3. 在weblogic11g上发布项目遇到的一个错误(不支持web-app_3_0)

    错误信息如下: 消息图标 - 错误 [HTTP:101064][WebAppModule(ssh1:ssh1.war)] Error parsing descriptor in Web appplic ...

  4. StrictMode对SharedPreferences的检查出来的IO操作

    在使用StrictMode时,发现会爆出 StrictMode policy violation;~duration=1949 ms: android.os.StrictMode$StrictMode ...

  5. Unity小厨房之-----背后视角摄像机

    相信每一个接触过Unity的人,应该都认识Unity引擎自带的那个水管工,也一定知道那个小人模型上挂着3个脚本控制着小人的一切,今天我就来说一下关于Unity背后视角摄像机的实现,当然方法并不唯一,这 ...

  6. 在线重定义(Rdefine Table online)

    二.        概念理解 在线重定义用于对表的逻辑或者物理结构的修改,而且在修改时不影响表的可用性与传统方式相比.当一个表被重定义时,会被锁定为exclusive mode很短一段时间,这段时间的 ...

  7. Android GridView 指定行数,动态行宽,占满空间

    有时间我们需要 使用GridViw 让它占满父控件,例: 特别是在适配的时间比较麻烦,在不同的机型上可能分出下,下面空的太多,或有滚动条问题,; 下面说一下实现思路: 首先,设置GridView 为三 ...

  8. Ogre参考手册(五)3.2 合成器

    3.2 合成器Compositor 合成器框架是Ogre用于全屏后处理的API.你可以通过脚本而不是API定义合成器.你可以很容易为视口实例化合成器. 合成器基础 无论是要替换还是要与主渲染窗口混合, ...

  9. Epic - Desirable Number

    A number is called 'desirable' if all thedigits are strictly ascending eg: 159 as 1<5<9. You k ...

  10. Markdown 编辑器语法指南

    基本技巧 代码 如果你只想高亮语句中的某个函数名或关键字,可以使用 `function_name()` 实现 通常编辑器根据代码片段适配合适的高亮方法,但你也可以用 ``` 包裹一段代码,并指定一种语 ...