/**
  * Finds the TrainTeachers model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return TrainTeachers the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = TrainTeachers::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #2
0
        <select style="width:200px" name="TrainTeachers[teachers_id]" class="form-control" id="trainteachers-teachers_id">
            <?php 
foreach (\app\models\Teachers::getAll() as $key => $val) {
    ?>
            <option value="<?php 
    echo $val['id'];
    ?>
" <?php 
    if ($model->teachers_id == $val['id']) {
        ?>
 selected <?php 
    }
    ?>
><?php 
    echo $val['name'];
    if (\app\models\TrainTeachers::findOne(['train_id' => $model->trainId, 'teachers_id' => $val['id']])) {
        ?>
———已选<?php 
    }
    ?>
</option>
            <?php 
}
?>
        </select>

        <div class="help-block"></div>
    </div>

    <div class="form-group">
        <?php