yii\helpers\BaseUrl::base PHP Method

base() public static method

Returns the base URL of the current request.
public static base ( boolean | string $scheme = false ) : string
$scheme boolean | string the URI scheme to use in the returned base URL: - `false` (default): returning the base URL without host info. - `true`: returning an absolute base URL whose scheme is the same as that in [[\yii\web\UrlManager::$hostInfo]]. - string: returning an absolute base URL with the specified scheme (either `http`, `https` or empty string for protocol-relative URL).
return string
    public static function base($scheme = false)
    {
        $url = static::getUrlManager()->getBaseUrl();
        if ($scheme !== false) {
            $url = static::getUrlManager()->getHostInfo() . $url;
            $url = static::ensureScheme($url, $scheme);
        }
        return $url;
    }

Usage Example

Beispiel #1
0
 public function actionRestore($id = null)
 {
     $model = new FormBackupFile();
     $comp = $this->loadModel($this->company);
     if (isset($_POST['FormBackupFile'])) {
         $bkup = Company::getFilePath() . "tmp.zip";
         $model->file = $_POST['FormBackupFile']['file'];
         $model->file = \yii\web\UploadedFile::getInstance($model, 'file');
         if ($model->file->saveAs($bkup)) {
             $comp->restore($bkup);
             return $this->redirect(\yii\helpers\BaseUrl::base() . '/settings/dashboard');
         }
     }
     if ($id != null) {
         $file = Files::findOne($id);
         if ($file != null) {
             $comp->restore($file->getFullFilePath());
             $this->redirect(\yii\helpers\BaseUrl::base() . '/settings/dashboard');
         } else {
             throw new \yii\web\HttpException(500, 'The backup file does not exist.');
         }
     }
     //read file
     //if DROP TABLE IF EXISTS `
     //if CREATE TABLE `
     //INSERT INTO `
     return $this->render('backupRestore', array('model' => $model));
 }
All Usage Examples Of yii\helpers\BaseUrl::base