yii2.0 DetailView Custom Styles

Source: Internet
Author: User

The GII generates the following:

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

The customizations are as follows:

 <?= detailview::widget ([ ' model ' =  [ ' id ',  ' label ' = ' name ', ' value ' => $model ->name)],] , ' template ' = ' <tr><th>{label}</th><td>{value}</td></tr> ', ' O ptions ' = = [' Class ' = ' table table-striped table-bordered detail-view '],? 
the HTML after the output is    : 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 > Other specific parameters, refer to "[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} ' is replaced with the label and the value of the corresponding attrib Ute. * If a callback (e.g. an anonymous function), the signature must is as follows: * * ~ ~ ~ function ($attribute, $index, $w  Idget) * ~ ~ ~ * 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's this widget. The "tag" option specifies * what container tag should is used. It defaults to the "table" if not set. * @see \yii\helpers\html::rendertagattributes () for details on how attributes is 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 is either an instance of [[[Formatter]] or a configuration array for creating the [[Formatter]] * instance. If The property was not set, the "formatter" application component would be used. */ Public $formatter;
$options can freely define, such as:<?= 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 '],]) ?>defined as Class1, the output HTML is:<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 >

This digest from: http://www.yiichina.com/question/418

yii2.0 DetailView Custom Styles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.