【问题标题】:work with Html::button in Yii 2在 Yii 2 中使用 Html::button
【发布时间】:2016-10-04 07:05:34
【问题描述】:

我在 Yii 2 中创建了一个网格视图,如下所示:

 <?= GridView::widget([
        'dataProvider'   => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\ActionColumn'],
            ['class' => 'kartik\grid\SerialColumn'],
            ['class' => 'kartik\grid\CheckboxColumn'],
            'id',
            'countrydate',
            'countryCode'=>[
                'attribute'=>'countryCode',
                'content' => function($model,$key,$index, $column) {
                    return Html::button($model->countryCode,$options = [
                        'onclick'=>'showcountryCode('.$key.')',
                        'id'=>'countryCode'.$key,
                        'class'=>'popup',
                    ]);
                }
            ],
            'countryName',
            'countrydate',
             'population',
             'fipsCode',

        ],

我使用我的 cutson 设置

'countryCode'=>[
                    'attribute'=>'countryCode',
                    'content' => function($model,$key,$index, $column) {
                        return Html::button($model->countryCode,$options = [
                            'onclick'=>'showcountryCode('.$key.')',
                            'id'=>'countryCode'.$key,
                            'class'=>'popup',
                        ]);
                    }
                ],

你知道我们可以像这样在 HTML 中互相包含标签:

<a> <h1> asdas </h1> </a>

现在我想在 Html::button 中添加另一个标签,我该怎么做?

【问题讨论】:

    标签: php html yii yii2


    【解决方案1】:

    Html::button()的定义是

    public static string button ($content = 'Button', $options = [])
    

    所以第一个参数是你想放入的任何东西。

    你可以使用纯 HTML

    Html::button('<b>xxx</b><span>yyyy</span>');
    

    或相同自定义标签的 Yii 2 静态 Html 方法:

    Html::button(Html::tag('b', 'xxx') . Html::tag('span', 'yyyy'));
    

    【讨论】:

      猜你喜欢
      • 2017-02-12
      • 2015-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      相关资源
      最近更新 更多