douchu4048 2015-11-04 15:55
浏览 209

yii2没有值的DetailView模板/布局

I have a little problem in yii2 framework.

  1. I have DetailView widget

                    <?= DetailView::widget([
                        'model' => $table_1,
                        'attributes' => [
                            'year',
                            'table_zs_field_1',
                            'table_zs_field_2',
                            'table_zs_field_3',
                            'table_zs_field_4',
                            'table_zs_field_5',
                            'table_zs_field_6',
                            'table_zs_field_7',
                            'table_zs_field_8',
                            'table_zs_field_9',
                            'table_zs_field_10',
                            'table_zs_field_11',
                            'table_zs_field_12',
                            'table_zs_field_13',
                            'table_zs_field_14',
                            'table_zs_field_15',
                            'table_zs_field_16',
                            'table_zs_field_17',
                            'table_zs_field_18',
                            'table_zs_field_19',
                        ],
                    ]) ?>
    
  2. If i write this to code I'll see a DetailView widget with names of fields(get from model) and values.

  3. Problem: I want to hide values and show only names of fields from model and in next time hide names and show only values. Anybody know ?

  • 写回答

1条回答 默认 最新

  • dtol41388 2015-11-04 15:59
    关注

    Change the $template property of the Detailview. The Default is

    $template = '<tr><th>{label}</th><td>{value}</td></tr>'
    

    Adding

    'template'=>'<tr><th>{label}</th></tr>' ,
    

    to the config array of your DetailView should show only the names of the fields. Adding

    'template'=>'<tr><td>{value}</td></tr>',
    

    should show only the value.

    See the corresponding section in the Documentation of DetailView.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型