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. Spring 的 BeanPostProcessor接口实现

    今天学习了一下Spring的BeanPostProcessor接口,该接口作用是:如果我们需要在Spring容器完成Bean的实例化,配置和其他的初始化后添加一些自己的逻辑处理,我们就可以定义一个或者 ...

  2. Jenkins参数化构建

    背景:每次构建项目时都需要去修改一下配置,然后保存,再去立即构建.这样修改容易修改出错误,影响到执行脚本,且每次都要去修改配置,不容易修改,操作也比较麻烦.所以决定将Jenkins修改为参数化构建.下 ...

  3. java异常处理机制throws

    throws可以在方法声明时抛出的异常.原则上throws声明的异常,一定要在该方法中抛出,否则没有意义. 相反的,若方法中我们主动通过throw抛出一个异常,应该在throws中声明该种类异常,通知 ...

  4. linux双机GFS的配置

    1.两台服务器安装如下包: apr-1.2.7-11.el5_3.1.x86_64.rpmapr-util-1.2.7-11.el5.x86_64.rpmcman-2.0.115-34.el5.x86 ...

  5. [POJ 1155] TELE (树形dp)

    题目链接:http://poj.org/problem?id=1155 题目大意:电视台要广播电视节目,要经过中转机构,到观众.从电视台到中转商到观众是一个树形结构,经过一条边需要支付成本.现在给你每 ...

  6. UITableViewCell之微博篇

    微博篇 本应用所涉及的知识点: 1.UITableView 中的cell 2.模型的创建 3.MJExtension第三方框架的使用 需求分析 1.界面分析 微博界面 界面控件分析: 整个页面 1.不 ...

  7. (转)直接拿来用!最火的iOS开源项目(一)

    1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...

  8. Web自动化框架LazyUI使用手册(2)--先跑起来再说(第一个测试用例-百度搜索)

    作者:cryanimal QQ:164166060 上篇文章中,简要介绍了LazyUI框架,本文便来演示,如何从无到有快速搭建基于lazyUI的工程,并成功运行第一个测试用例. 本文以百度搜索为例,选 ...

  9. 刻意练习,逃离舒适区——怎么样成为一个高手[罗辑思维]No.183_知识笔记

    2016/10/30 14:31:32   一.对事物的见解分为两类:         1.评论性的见解               说的内容都是对的,符合常理的,但是却是不解决问题的.       ...

  10. Android开发-API指南-<activity-alias>

    <activity-alias> 英文原文:http://developer.android.com/guide/topics/manifest/activity-alias-elemen ...