Answer the question
In order to leave comments, you need to log in
How to make a model?
Hello, I'm just starting to learn yii, I want to make a site with tests, a controller model and a view for the form, I'm attaching the
Model below
<?php
namespace app\models;
use yii\base\Model;
class QuizForm extends Model
{
public $radio1;
public function rules()
{
return [
[['radio1'], 'required'],
];
}
}
<?php
namespace app\controllers;
use Yii;
use app\models\QuizForm;
use yii\web\Controller;
class QuizController extends Controller
{
public function actionIndex()
{
$model = new QuizForm();
if ($model->load(Yii::$app->request->post()) && $model->validate())
{
return $this->render('res', ['model' => $model]);
}
else
{
return $this->render('index', ['model' => $model]);
}
}
}
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<div class="tests-content">
<div class="test-title">
Тест 1. HTML5 теги
</div>
<?php $form = ActiveForm::begin(); ?>
<div class="test-variants">
<?= $form->field($model, 'radio1')->radioList( [1=>'Для вставки изображения', 2 => 'Для отправки данных', 3 => 'Для вставки пробела'] )->label(' Для чего предназначен тег img ?'); ?>
</div>
<div class="test-buttons">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question