Yii 2 Bootstrap Button

How do I get the button to go to a URL?

In Yii 1 we use to have a URL property, do we still have that?

Surprised no one has answered this, anyone round here use the Bootstrap buttons?

How do you get it to link to a URL?

In the old Yii buttons use to have a URL parameter?

From what I can see the HTML rendered is a Button element so I cannot use htmlOptions href etc.

Can you show with HTML what you want to do?

Yes I could do it with HTML, but I am trying to use the Yii button.

Like this …




<?php echo Button::widget(["label" => "Create", "options" => ["class" => "btn-primary grid-button"]]); ?>



But where do I put the URL? Should be like this, but there no URL property …




<?php echo Button::widget(["url" => ["user/create"], label" => "Create", "options" => ["class" => "btn-primary grid-button"]]); ?>



Something like this?




echo Button::widget([

    'label' => 'Create',

    'options' => ['class' => 'btn-primary grid-button', 'href' => Url::to(["user/create"])],

]);



I will try it, but the html it renders is a button element and I am sure html does not have a href property on a button element.

you can use link instead of button with href attributes, see this code:


<?= Html::a('Create', ['/user/create'], ['class'=>'btn btn-primary grid-button']) ?>

you can use toUrl to create custom URL: to()

Hope it works fine

Hi Abed,

Yes it works, thanks.

James.