yupe\helpers\YFile::rmIfExists PHP Method

rmIfExists() public static method

public static rmIfExists ( $file ) : boolean
$file
return boolean
    public static function rmIfExists($file)
    {
        if (!file_exists($file)) {
            return true;
        }
        if (is_dir($file)) {
            return static::rmDir($file);
        }
        return static::rmFile($file);
    }

Usage Example

 public function actionRegenerate()
 {
     if (!Yii::app()->getRequest()->getIsPostRequest() || !Yii::app()->getRequest()->getPost('do')) {
         throw new CHttpException(404);
     }
     if (\yupe\helpers\YFile::rmIfExists($this->getModule()->getSiteMapPath())) {
         Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('SitemapModule.sitemap', 'Sitemap is deleted!'));
         Yii::app()->ajax->success();
     }
     Yii::app()->getUser()->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('SitemapModule.sitemap', 'Sitemap is not deleted!'));
     Yii::app()->ajax->failure();
 }
All Usage Examples Of yupe\helpers\YFile::rmIfExists