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. Notepad++隐藏的用法

    Notepad++是一个非常强大的文本编辑器. 它里面有很多有用的插件. 我认为对我比较有帮助的一个是NppExporter.它可以将Notepad++中彩色的代码原样的复制到Word中. 想要获得彩 ...

  2. WPF NotifyIcon and Taskbar 任务栏示例

    Demo Source 转自:http://www.codeproject.com/Articles/36788/WPF-XAML-NotifyIcon-and-Taskbar-System-Tray ...

  3. [SQL]把同一字段里的多行数据用一行显示

    declare @t table(id int,num int) insert @t , union all , union all , --select * from @t ----查询 decla ...

  4. 巧用Freemarker的自定义方法

    要想使用Freemarker支持的自定义方法,需要实现freemarker.template.TemplateMethodModel接口,然后将方法对象放入到Freemarker的数据模型中,这样在f ...

  5. HDU 3535 【背包】

    题意: 给出n组数据,每组数据有一个类型. 0代表至少选择一个,1代表至多选择一个,2代表任意选择. 给出背包容量. 如果背包不能满足最基本的要求输出-1. 思路: 背包问题变相考察~ 当0的时候初始 ...

  6. WPF异步调用

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

  7. BC之The mook jong

    Problem Description ZJiaQ want to become a strong man, so he decided to play the mook jong.ZJiaQ wan ...

  8. 在Yarn上运行spark-shell和spark-sql命令行

    转载自:http://lxw1234.com/archives/2015/08/448.htm 如果你已经有一个正常运行的Hadoop Yarn环境,那么只需要下载相应版本的Spark,解压之后做为S ...

  9. OC基础(18)

    Category基本概念 Category注意事项 *:first-child { margin-top: 0 !important; } body > *:last-child { margi ...

  10. NHibernate 中使用 nvarchar(max) 类型

    在 NHibernate 中使用字符串类型,默认会映射到字符类型,在 SQLServer 中,NVARCHAR 类型最大长度是 4000 字符,如果超过 4000,比如使用 SQL Server 中的 ...