Bolt\Canonical::getUrl PHP Метод

getUrl() публичный Метод

Returns the canonical url for the current request, or null if called outside of the request cycle.
public getUrl ( ) : string | null
Результат string | null
    public function getUrl()
    {
        if (($request = $this->requestStack->getCurrentRequest()) === null) {
            return null;
        }
        return $this->urlGenerator->generate($request->attributes->get('_route'), $request->attributes->get('_route_params'), UrlGeneratorInterface::ABSOLUTE_URL);
    }

Usage Example

Пример #1
0
 /**
  * Add base snippets to the response.
  */
 protected function addSnippets()
 {
     $generatorSnippet = (new Snippet())->setLocation(Target::END_OF_HEAD)->setCallback('<meta name="generator" content="Bolt">');
     $this->queue->add($generatorSnippet);
     $canonicalUrl = $this->canonical->getUrl();
     $canonicalSnippet = (new Snippet())->setLocation(Target::END_OF_HEAD)->setCallback($this->encode('<link rel="canonical" href="%s">', $canonicalUrl));
     $this->queue->add($canonicalSnippet);
     if ($favicon = $this->config->get('general/favicon')) {
         $faviconUrl = $this->packages->getUrl($favicon, 'theme');
         $faviconSnippet = (new Snippet())->setLocation(Target::END_OF_HEAD)->setCallback($this->encode('<link rel="shortcut icon" href="%s">', $faviconUrl));
         $this->queue->add($faviconSnippet);
     }
 }