/** * @param $id * @return $this * @throws NotFoundHttpException * @throws \yii\web\HttpException */ public function actionAttachmentDownload($id) { $model = ArticleAttachment::findOne($id); if (!$model) { throw new NotFoundHttpException(); } return Yii::$app->response->sendStreamAsFile(Yii::$app->fileStorage->getFilesystem()->readStream($model->path), $model->name); }
/** * @return \yii\db\ActiveQuery */ public function getArticleAttachments() { return $this->hasMany(ArticleAttachment::className(), ['article_id' => 'id']); }