Flarum\Foundation\Application::url PHP Method

url() public method

Get the URL to the Flarum installation.
public url ( string $path = null ) : string
$path string
return string
    public function url($path = null)
    {
        $config = $this->isInstalled() ? $this->make('flarum.config') : [];
        $url = array_get($config, 'url', array_get($_SERVER, 'REQUEST_URI'));
        if (is_array($url)) {
            if (isset($url[$path])) {
                return $url[$path];
            }
            $url = $url['base'];
        }
        if ($path) {
            $url .= '/' . array_get($config, "paths.{$path}", $path);
        }
        return $url;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function getDefaultAttributes($model)
 {
     $attributes = ['title' => $this->settings->get('forum_title'), 'description' => $this->settings->get('forum_description'), 'baseUrl' => $url = $this->app->url(), 'basePath' => parse_url($url, PHP_URL_PATH) ?: '', 'debug' => $this->app->inDebugMode(), 'apiUrl' => $this->app->url('api'), 'welcomeTitle' => $this->settings->get('welcome_title'), 'welcomeMessage' => $this->settings->get('welcome_message'), 'themePrimaryColor' => $this->settings->get('theme_primary_color'), 'themeSecondaryColor' => $this->settings->get('theme_secondary_color'), 'logoUrl' => $this->getLogoUrl(), 'faviconUrl' => $this->getFaviconUrl(), 'headerHtml' => $this->settings->get('custom_header'), 'allowSignUp' => (bool) $this->settings->get('allow_sign_up'), 'defaultRoute' => $this->settings->get('default_route'), 'canViewDiscussions' => $this->actor->can('viewDiscussions'), 'canStartDiscussion' => $this->actor->can('startDiscussion')];
     if ($this->actor->can('administrate')) {
         $attributes['adminUrl'] = $this->app->url('admin');
         $attributes['version'] = $this->app->version();
     }
     return $attributes;
 }
All Usage Examples Of Flarum\Foundation\Application::url