/**
  * Updates an existing ClassRooms model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         ClassType::deleteAll('classroom_id = ' . $model->classrooms_id);
         $spec_classes_array = $model->options;
         foreach ($spec_classes_array as $key) {
             $ctype = new ClassType();
             $ctype->classroom_id = $model->classrooms_id;
             $ctype->spec_class_id = $key;
             $ctype->insert();
         }
         return $this->redirect(['view', 'id' => $model->classrooms_id]);
     } else {
         $opt = ClassType::findAll(['classroom_id' => $_GET['id']]);
         foreach ($opt as $key) {
             $optArr[] = $key['spec_class_id'];
         }
         $model->options = $optArr;
         return $this->render('update', ['model' => $model]);
     }
 }
示例#2
0
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use app\module\handbook\models\ClassType;
use app\module\handbook\models\Specclasses;
/* @var $this yii\web\View */
/* @var $model app\module\handbook\models\ClassRooms */
$this->title = 'Аудиторія №' . $model->classrooms_number;
$this->params['breadcrumbs'][] = ['label' => 'Аудиторії', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$optionsId = ClassType::findAll(['classroom_id' => $model->classrooms_id]);
for ($i = 0; $i < count($optionsId); $i++) {
    $optionName[] = Specclasses::findAll(['spec_class_id' => $optionsId[$i]['spec_class_id']]);
    $optionsArray[] = $optionName[$i][0]['spec_class_name'] . " ";
}
$optionsString = implode($optionsArray);
function translater($val)
{
    if ($val == 0) {
        return "Ні";
    } else {
        return "Так";
    }
}
?>
<div class="classrooms-view">

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