yii2.0 DetailView 自定义样式
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 自定义样式的更多相关文章
- yii2.0保留CSS样式的引入
<link rel="stylesheet" href="http://cdn.staticfile.org/twitter-bootstrap/3.2.0/css ...
- 7.Yii2.0框架自定义全局工具函数
功能: 新建共用方法的打印方法,可以很方便的格式化打印 一.新建helper/function.php <?php /** * Created by Haima. * Author:Haima ...
- yii2.0 如何按需加载并管理CSS样式及JS脚本
链接:http://www.yiichina.com/tutorial/399 (注:以下为Yii2.0高级应用测试) Yii2.0对于CSS/JS 管理,使用AssetBundle资源包类. 视图如 ...
- Yii2 ActiveForm表单自定义样式
实例: <?php $form = ActiveForm::begin([ 'fieldConfig' => [ 'template' => '<div class=" ...
- 教你在Yii2.0框架中如何创建自定义小部件
本教程将帮助您创建自己的自定义小部件在 yii framework 2.0.部件是可重用的模块和用于视图. 创建一个小部件,需要继承 yii\base\Widget,覆盖重写 yii\base\Wid ...
- yii2.0下拉列表的使用
第一种方法:ActiveForm 类的 dropDownList 方法(优点,默认使用yii的样式) 1.在控制器的方法里面 ,我们需要拿到数据,一定是 findAll() 或者是 all() 方法的 ...
- 一步步开发自己的博客 .NET版 剧终篇(6、响应式布局 和 自定义样式)
前言 这次开发的博客主要功能或特点: 第一:可以兼容各终端,特别是手机端. 第二:到时会用到大量html5,炫啊. 第三:导入博客园的精华文章,并做分类.(不要封我) 第四:做 ...
- Android RatingBar 自定义样式
Android RatingBar 自定义样式 1.先定义Style: <style name="RadingStyle" parent="@android:sty ...
- 自定义样式RatingBar的使用
1.设置布局文件,自定义ratingbar样式 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an ...
随机推荐
- 8 个 Git 的小技巧
git 已经成为了我日常必备工具之一,我总结我几乎每天使用的8个有用(且简洁)的git技巧. 使用-p选择性添加 当你想提交内容时,你可以通过使用 git commit -am 来选择所有文件或使 ...
- ubuntu命令查补
Linux删除目录的命令有:rm,rm命令删除目录虽说比较简单,不过一旦所操作的目录非空时,就会让你陷入深深的苦恼之中 rm -rf 目录名字: -r 就是向下递归,管理有多少级目录,一并删除 -f ...
- BC之The mook jong
Problem Description ZJiaQ want to become a strong man, so he decided to play the mook jong.ZJiaQ wan ...
- [Android疑难杂症]动态改变Background后Padding无效的问题
前言 在Layout中指定好background和padding以后,程序里面动态修改background之后padding就失效了,貌似是一个BUG,这里找到了一篇英文文章,简单翻译分享一下. 声明 ...
- (转)ASP.NET MVC4 部署错误 Could not load file or assembly
使用VS2010 测试ASP.NET MVC 4 Web API 在部署时候遇到了问题,发现园友有解决的方式,因此转载. 我的解决方式有两种:使用VS2015将VS2010的项目重新发 ...
- Troubleshooting 'library cache: mutex X' Waits.
What is a 'library cache: mutex X' wait? The mutex feature is a mechanism to control access to in me ...
- CInternetSession CHttpFile Post提交数据
//给指定url发请求, 返回请求后的结果 string CAutoPatchDlg::SendURLPost(string strServerName, string strFormActionUr ...
- 【CImg】简单的畸变矩形矫正
三个角点确定一个平面,畸变的平面可以看成是不同基底下同一图像的表示 ============================我是分割线============================= 1. ...
- flex安装时停在计算时间界面的解决办法
现象:安装FLEX BUILDER4.6时停在计算时间界面,过了一会后弹出安装失败的对话框. 环境:WIN7 解决: 1.下载AdobeCreativeCloudCleanerTool, 地址:htt ...
- tornado框架之路一
Web 服务器 每个页面都以 HTML 的形式传送到你的浏览器中,HTML 是一种浏览器用来描述页面内容和结构的语言.那些负责发送 HTML 到浏览器的应用称之为“Web 服务器”,会让你迷惑的是,这 ...