Exemplo n.º 1
0
 /**
  * Creates a new Articles model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Articles();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         /** @var Teachers[] $teachers */
         $teachers = Teachers::find()->where(['id' => $model->id_teacher])->all();
         foreach ($teachers as $teacher) {
             $model->link('teachers', $teacher);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', array('model' => $model, 'modelTeacher' => ArrayHelper::map(Teachers::find()->all(), 'id', 'userSurname', 'userName')));
     }
 }