Пример #1
0
 /**
  * Finds the Docfiles model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Docfiles the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Docfiles::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 public static function DeleteDocFile($docfile_id)
 {
     if (!empty($docfile_id)) {
         $existdb1 = RraDocfiles::find()->andWhere(['id_docfiles' => $docfile_id])->count();
         $existdb2 = RramatDocfiles::find()->andWhere(['id_docfiles' => $docfile_id])->count();
         if (empty($existdb1) && empty($existdb2)) {
             $Docfiles = Docfiles::findOne($docfile_id);
             if (!empty($Docfiles)) {
                 $hash = Yii::$app->basePath . '/docs/' . $Docfiles->docfiles_hash;
                 $fileroot = DIRECTORY_SEPARATOR === '/' ? $hash : mb_convert_encoding($hash, 'Windows-1251', 'UTF-8');
                 if ($Docfiles->delete() && file_exists($fileroot)) {
                     return unlink($fileroot);
                 }
             }
         }
     }
     return false;
 }