'raw', 'contentOptions'=>['style'=>'widt...">

Set href = "#" or unset html :: a href from grid-view yii2

I have the following code:

 [   'format' => 'raw',
            'contentOptions'=>['style'=>'width: 5px;'],
            'value' => function($model) {
                if($model->id == Yii::$app->user->identity->id) {
                    return  Html::a('<i class="glyphicon glyphicon-share-alt"></i>',[''],['id'=> 'replay-to-'. $model->ID_KOMENTAR ]).' '. 
                            Html::a('<i class="glyphicon glyphicon-pencil"></i>', ['update', 'id' => $model->id]).' '.
                            Html::a('<i class="glyphicon glyphicon-trash"></i>', ['delete', 'id' => $model->id], ['data' => ['confirm' => 'Do you really want to delete this element?','method' => 'post']]);
                }
                return Html::a('<i class="glyphicon glyphicon-share-alt"></i>',['feedback', 'id' => $model->id],['id'=> 'replay-to-'. $model->ID_KOMENTAR ]);
            },
        ],

I need a repeat button to avoid href, which makes my page redirected to another page because I want to click and put jquery there.

I tried with this:

Html::a('<i class="glyphicon glyphicon-share-alt"></i>',[''],['id'=> 'replay-to-'. $model->ID_KOMENTAR ])

but it is still redirected to another page.

+4
source share
2 answers

To set a hrefvalue #:

Html::a('<i class="glyphicon glyphicon-share-alt"></i>', '#', ['id'=> 'replay-to-' . $model->ID_KOMENTAR]);

HTML output will be:

<a id="replay-to-1" href="#"><i class="glyphicon glyphicon-share-alt"></i></a>

To completely remove an attribute href, use null(and its default value for the second parameter):

Html::a('<i class="glyphicon glyphicon-share-alt"></i>', null, ['id'=> 'replay-to-' . $model->ID_KOMENTAR]);

HTML output will be:

<a id="replay-to-1"><i class="glyphicon glyphicon-share-alt"></i></a>
+2
source

try it

Html::a('<i class="glyphicon glyphicon-share-alt"></i>', false, ['id'=> 'replay-to-'. $model->ID_KOMENTAR ]);

+1
source

Source: https://habr.com/ru/post/1605661/


All Articles