/** * Creates a new Artist model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Artist(); $photos = []; if (Yii::$app->request->isPost) { for ($i = 0; $i < count(Yii::$app->request->post('Photo', [])); $i++) { $photos[] = new Photo(); } $data = Yii::$app->request->post(); $data['Artist']['user_id'] = Yii::$app->user->id; } else { $data = null; } if ($model->load($data) && $model->save()) { Photo::loadMultiple($photos, Yii::$app->request->post()); foreach ($photos as $photo) { $photo->artist_id = $model->id; } if (Photo::validateMultiple($photos)) { foreach ($photos as $photo) { $model->link('photos', $photo); } } $tags = Yii::$app->request->post('Artist', ''); $tags = Tag::find()->where(['in', 'id', explode(',', $tags['tags'])])->all(); foreach ($tags as $tag) { $model->link('tags', $tag); } return $this->redirect(['release/index', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'photos' => $photos]); } }