/** * Finds the Cover model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Cover the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Cover::findOne($id)) !== null) { if ($model->file->user_id != Yii::$app->user->id) { throw new \yii\web\ForbiddenHttpException(); } return $model; } else { throw new \yii\web\NotFoundHttpException('The requested page does not exist.'); } }
public function actionCover() { $model = Cover::findOne(Yii::$app->request->post('pk', '')); $ownerId = $model->file->user_id; return self::update($model, $ownerId); }