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.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料