Answer the question
In order to leave comments, you need to log in
Cannot redeclare radio() error, why?
I don’t understand why my function does not work, it writes an error
Cannot redeclare radio() (previously declared in C:\OpenServer\domains\hostTraining\frontend\views\test\update.php:6)
function radio($answer, $right, $number){
if ($answer == $right){
return '<label><input type="radio" name="right" class="radio radio-'.$number.'" value="'.$answer.'" checked><span>Правильный</span></label>';
} else {
return '<label><input type="radio" name="right" class="radio radio-'.$number.'" value="'.$answer.'" checked><span>Правильный</span></label>';
}
}
<?= Html::beginForm(['test/update', 'id' => $model->id], 'post') ?>
<div>
<label>Вопрос </label>
<?= Html::input('text', 'Question', $model->name, ['class' => ['form-control']]) ?>
</div>
<div>
<label>Ответ 1 </label>
<?php echo Html::input('text', 'Answer[1]', $answer[1], ['class' => 'answer-1']);
if ($answer[1] == $right){
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[1].'" checked><span>Правильный</span></label>';
} else {
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[1].'"><span>Правильный</span></label>';
}
</div>
<div>
<label>Ответ 2 </label>
<?php echo Html::input('text', 'Answer[2]', $answer[2], ['class' => 'answer-2']);
if ($answer[2] == $right){
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[2].'" checked><span>Правильный</span></label>';
} else {
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[2].'"><span>Правильный</span></label>';
}
</div>
<div>
<label>Ответ 3 </label>
<?php echo Html::input('text', 'Answer[3]', $answer[3], ['class' => 'answer-3']);
if ($answer[3] == $right){
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[3].'" checked><span>Правильный</span></label>';
} else {
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[3].'"><span>Правильный</span></label>';
}
</div>
<div>
<label>Ответ 4 </label>
<?php echo Html::input('text', 'Answer[4]', $answer[4], ['class' => 'answer-4']);
if ($answer[4] == $right){
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[4].'" checked><span>Правильный</span></label>';
} else {
echo '<label><input type="radio" name="right" class="radio radio-1" value="'.$answer[4].'"><span>Правильный</span></label>';
}
</div>
<?php echo FileInput::widget(['name' => 'attachment[]']) ?>
<div class="form-group">
<?= Html::submitButton('Редактировать', ['class' => 'btn btn-primary']); ?>
<?= Html::a('Удалить', ['test/delete', 'id' => $model->id], ['class' => 'btn btn-danger']) ?>
</div>
<?= Html::endForm() ?>
Answer the question
In order to leave comments, you need to log in
Cannot redeclare radio() (previously declared in C:\OpenServer\domains\hostTraining\frontend\views\test\update.php:6)
The problem is that you already have one function called radio, and you can't just declare a second one with the same name.
And in general, you have noodles there . Do not do it this way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question