<?php foreach ($model as $count => $question){
$number = $count+1;
...
Modal::begin([
'header' => 'Редактирование',
'toggleButton' => [
'tag' => 'span',
'class' => 'glyphicon glyphicon-edit'
]
]);
$modelQuestion = Questions::findOne($question->id);
echo $this->render('update', ['model' => $modelQuestion]);
Modal::end();
echo '</div>';
...
} ?>
echo '<span class="glyphicon glyphicon-edit editQuestion" data-path="'. Url::to(['test/update', 'id' => $question->id]).'"></span></div>';
<?php Modal::begin([
'id' => 'modal-editQuestion',
'header' => 'Редактировние вопроса',
]);
echo '<div class="modal-content"></div>';
Modal::end(); ?>
$('.editQuestion').click(function(){
let path = $(this).data('path');
console.log(path);
$('#modal-editQuestion').modal('show')
.find('.modal-content')
.load(path);
});
Modal::begin([
'header' => 'Редактирование',
'toggleButton' => [
'tag' => 'span',
'class' => 'glyphicon glyphicon-edit'
]
]);
$modelQuestion = Questions::findOne($question->id);
echo $this->render('update', ['model' => $modelQuestion]);
Modal::end();
require_once
но ничего не изменилось $correct = function($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>';
}
};
echo $correct($answer[1], $right, 1);
<?php
use yii\helpers\Html;
use kartik\file\FileInput;
$right = $model->correct['right'];
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>';
}
}
$answer = $model->answear;
?>
<h3>Редактирование вопроса</h3>
<?= 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']);
echo radio($answer[1], $right, 1); ?>
</div>
<div>
<label>Ответ 2 </label>
<?php echo Html::input('text', 'Answer[2]', $answer[2], ['class' => 'answer-2']);
echo radio($answer[2], $right, 2); ?>
</div>
<div>
<label>Ответ 3 </label>
<?php echo Html::input('text', 'Answer[3]', $answer[3], ['class' => 'answer-3']);
echo radio($answer[3], $right, 3); ?>
</div>
<div>
<label>Ответ 4 </label>
<?php echo Html::input('text', 'Answer[4]', $answer[4], ['class' => 'answer-4']);
echo radio($answer[4], $right, 4); ?>
</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() ?>
public function actionUpdate($id)
{
$model = Questions::findOne($id);
$request = Yii::$app->request;
if ($request->post()){
$model->name = $request->post('Question');
$model->answear = json_encode($request->post('Answer'), JSON_UNESCAPED_UNICODE);
$model->correct = '{"right": "'.$request->post('right').'"}';
if (!$model->save()){
print_r($model->getErrors());
}
return $this->redirect(['test/test', 'id' => $model->id_theme]);
}
return $this->renderPartial('update', [
'model' => $model
]);
}