Example #1
0
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = $title;
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="teacher-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <?php 
if ($this->context->action->id == 'index') {
    ?>
    <p>
        <?php 
    echo Html::a('Добавить учителя', ['create'], ['class' => 'btn btn-success']);
    ?>
    </p>
    <?php 
}
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['attribute' => 'gender', 'content' => function ($data) {
    return $data->getGenderName();
}, 'filter' => Teacher::getGendersList()], 'phone', 'students_count', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Example #2
0
/* @var $model app\models\Teacher */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="teacher-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'gender')->dropDownList(Teacher::getGendersList());
?>

    <?php 
echo $form->field($model, 'phone');
?>

    <?php 
$studentsList = Student::find()->select(['id', 'name as text'])->where(['id' => $model->students_list])->orderBy('text')->asArray()->all();
$data = [];
$studentsListIdsByName = [];
foreach ($studentsList as $student) {
    $data[$student['id']] = $student;
    $studentsListIdsByName[] = $student['id'];
}
$model->students_list = $studentsListIdsByName;