GEOFFREY MWANGI GEOFFREY MWANGI - 1 month ago 17
PHP Question

Preselecting an active radiolist in yii2

Am using an activeradiolist in my form and i would like to have the first item selected but this fails

This isthe radiolist:

<?=Html::activeRadioList($model, is_normal, [1 => 'Customer truck', 2 => 'Transporter truck '])?>


I have tried

<?=
$model->is_normal = 1;
Html::activeRadioList($model, is_normal, [1 => 'Customer truck', 2 => 'Transporter truck '])?>


The above hides the radiolist and displays 1 on the screen.

How do i go about it

Answer

You are echoing the 1.

<?= is short for <?php echo.

Change the code to:

<?php
$model->is_normal = 1;
echo Html::activeRadioList($model, 'is_normal', [1 => 'Customer truck', 2 => 'Transporter truck ']);
?>