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. Eclipse中对Python代码自动格式化!

    在Eclipse中使用PyDev发现无法进行代码格式化,使用通常的"Ctrl+Shift+F"快捷键,没有任何变化,难道不能对python代码格式化了吗? 通过下面设置,就可以每次 ...

  2. cursor详解

    源地址:http://www.cnblogs.com/jiewoyishengwzm/archive/2010/06/08/1754232.html 查询 SELECT语句用于从数据库中查询数据,当在 ...

  3. 将access数据库导入mysql

    一般地,直接在mysql端,导入时选择access文件就行:但是若access数据库版本太老,导入mysql时会出错: 这时,就需要借助access 2003,对原始数据进行转换为2003版本数据,即 ...

  4. [SQL]reName存储过程

    exec sp_helptext aa--应用sp_helptext查看存储过程的定义文本 exec sp_depends aa --通过sp_depends查看存储过程的相关性 exec sp_he ...

  5. [POJ 1787]Charlie's Change (动态规划)

    题目链接:http://poj.org/problem?id=1787 题意:有4种货币分别是1元,5元,10元,20元.现在告诉你这四种货币分别有多少个,问你正好凑出P元钱最多可以用多少货币.每种货 ...

  6. WPF异步调用

    this.Dispatcher.BeginInvoke(new Action(()=> this.textBlock1.Text = DateTime.Now.ToString("HH ...

  7. JavaScript == VS ===

    引用自  http://fxk2006.iteye.com/blog/768260 ==   equality 等同,两边值类型不同的时候,要先进行类型转换,再比较. === identity 恒等, ...

  8. svn 常用操作命令

    svn 常用操作命令 检出 svn checkout http://路径(目录或文件的全路径) [本地目录全路径] --username 用户名 svn checkout svn://路径(目录或文件 ...

  9. python(二)拾遗

    1.int 系统内部自动执行的 a=123>>>>a=int(123)>>>>a=_init_(123) 外部调用 a 2 b=a.bit_length ...

  10. UIBlurEffect实现模糊效果

    //使用图片初始化背景 Pattern 图案,模式 self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageN ...