コード例 #1
0
 public function actionDeleteFile()
 {
     $request = Yii::$app->request;
     if ($request->post('id')) {
         $id = (int) $request->post('id');
         $model = FileList::findOne($id);
         if ($model === null) {
             throw new \yii\web\HttpException(404, Yii::t('Admin', 'File not found'));
         }
         if ($model->delete()) {
             $this->deleteFile($model->directory->path . '/' . $model->name);
             $request->headers->add('HTTP/1.1 201 Created', '');
         }
         $request->headers->add('HTTP/1.1 400 Bad request', '');
         if ($request->isAjax) {
             $request->headers->add('HTTP/1.1 201 Created', '');
             return $this->renderAjax('deleteFile_json', ['model' => $model, 'status' => true]);
         }
     } else {
         throw new HttpException(403, Yii::t('yii', 'You are not authorized to perform this action.'));
     }
 }
コード例 #2
0
 public function testIssetFile()
 {
     $model = FileList::findOne(2);
     $this->assertEquals(2, $model->id);
 }