/** * @return \yii\db\ActiveQuery */ public function getOtherCathedra() { return $this->hasMany(TeachersOtherCathedra::className(), ['id_teacher' => 'teacher_id']); }
<?php use yii\helpers\Html; use yii\widgets\DetailView; use app\module\handbook\models\TeachersOtherCathedra; use app\module\handbook\models\Cathedra; /* @var $this yii\web\View */ /* @var $model app\module\handbook\models\Teachers */ $this->title = $model->teacher_name; $this->params['breadcrumbs'][] = ['label' => 'Викладачі', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; $optionsId = TeachersOtherCathedra::findAll(['id_teacher' => $model->teacher_id]); for ($i = 0; $i < count($optionsId); $i++) { $optionName[] = Cathedra::findAll(['cathedra_id' => $optionsId[$i]['id_cathedra']]); $optionsArray[] = $optionName[$i][0]['cathedra_name'] . " "; } $optionsString = implode($optionsArray); ?> <div class="teachers-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a('Оновити', ['update', 'id' => $model->teacher_id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Видалити', ['delete', 'id' => $model->teacher_id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
/** * Deletes an existing Teachers model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { TeachersOtherCathedra::deleteAll('id_teacher = ' . $id); $this->findModel($id)->delete(); return $this->redirect(['index']); }