H
H
hollanditkzn2018-02-13 09:17:37
PHP
hollanditkzn, 2018-02-13 09:17:37

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)

When I turn on the function
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>';
    }
}

It's just so much less for me to write than to constantly announce
<?= 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() ?>

Who can say what is the problem?
Here is the whole file on gitgube https://github.com/hollandit/trainingYii/blob/mast...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-02-13
@hollanditkzn

Cannot redeclare radio() (previously declared in C:\OpenServer\domains\hostTraining\frontend\views\test\update.php:6)

The interpreter tells you that it cannot redefine the function, it is already defined in the update.php file on line 6. And this file is connected to the current one.

S
Stalker_RED, 2018-02-13
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question