/** * 先检查文件是否被使用没有使用则删除,在beforedelete中 * 尝试删除文件. * * @param unknown $id */ public function deleteFile($id) { $isUse = AttachmentIndex::find()->where(['attachment_id' => $id])->count(); if ($isUse > 0) { return false; } $file = Attachment::findOne(['attachment_id' => $id]); $file->delete(); }
/** * Finds the Attachment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param integer $id * @return Attachment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Attachment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }