Wijnand Wijnand - 2 months ago 67
PHP Question

yii2 button with link

I am trying to setup a button with a link to a view. However

yii/bootstrap/Button
does not have a property 'url'. I would rather use yii as supposed to just use flat out php. The code as below would be the ideal situation, but since the 'url' option does not exist, is there an other way to fix this using yii?

echo Button::Widget([
'label'=>'label',
'options'=>['class' => 'btn btn-primary'],
'url' => Url::toRoute(['/controller/action']),
]);

Answer

You could simply use Html::a() :

<?= Html::a('label', ['/controller/action'], ['class'=>'btn btn-primary']) ?>

Or create your own version of Button class to handle this.

PS: you don't need Url::toRoute

Comments