public function actionAdd() { $data = \Yii::$app->request->post('album'); if (isset($data)) { $album = new Albums(); $album->attributes = $data; $album->created = date("Y-m-d H:i:s"); $album->updated = $album->created; if (isset($data['date'])) { $date = new \DateTime($data['date']); $album->date = date_format($date, "Y-m-d H:i:s"); } if ($album->validate()) { $album->save(); return $album; } else { $ex = new ValidationException(); $ex->setData($album->errors); throw $ex; } } throw new BadRequestHttpException("Missing required parameters"); }
public function getAlbum() { return $this->hasOne(Albums::className(), ['album_id' => 'id']); }
public function actionAlbums() { $id_user = Yii::$app->request->get('id_user', 0); $albums = Albums::find()->where(['user_id' => $id_user])->all(); return $this->render('albums', ['albums' => $albums, 'user_id' => $id_user]); }