Answer the question
In order to leave comments, you need to log in
How to display an array in radioList in yii2?
there is a line in the post table where the json array is stored with the name of the sites and their links
. After Json::decode, this array takes this form
array(3) {
[0]=> array(2) {
["title"]=> string (90) "Site1"
["link"]=> string(32) " site1.ru "
}
[1]=> array(2) {
["title"]=> string(39) " Site2"
["link "]=> string(28) " site2.ru "
}
[2]=> array(2) {
["title"]=> string(56) "Site2"
["link"]=> string(27) " site3.en "
}
}
you need to list them in the radioList form so that the name is clickable
. here is the form itself, I don’t understand how to properly insert this array there.
<?= $form->field($model, 'site')->radioList([
//тут должен быть массив
], [
'item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="modal-radio">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3">';
$return .= '<i></i>';
$return .= '<span>' . ucwords($label) . '</span>';
$return .= '</label><br/>';
return $return;
}
]
); ?>
Answer the question
In order to leave comments, you need to log in
Good morning.
$arr = [
[
"title"=> "Сайт1",
"link"=> "site1.ru"
],
[
"title"=> " Сайт2",
"link"=> "site2.ru"
],
[
"title"=> "Сайт2",
"link"=> "site3.ru"
]
];
<?= $form->field($model, 'email')->radioList(ArrayHelper::map($arr, 'title', 'link'),[
'item' => function($index, $label, $name, $checked, $value) {
return '<label class="modal-radio" style="display:block;">
<input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3">
<i></i>
<span>' . ucwords($label) . '</span>
</label>';
}
]) ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question