Wijnand Wijnand - 10 months ago 257
PHP Question

yii2 button with link

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

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([
'options'=>['class' => 'btn btn-primary'],
'url' => Url::toRoute(['/controller/action']),


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