Class Phalcon\Mvc\Url

implements Phalcon\Mvc\UrlInterface, Phalcon\Di\InjectionAwareInterface

Source on GitHub

This components helps in the generation of: URIs, URLs and Paths

  1. <?php
  2. // Generate a URL appending the URI to the base URI
  3. echo $url->get("products/edit/1");
  4. // Generate a URL for a predefined route
  5. echo $url->get(
  6. [
  7. "for" => "blog-post",
  8. "title" => "some-cool-stuff",
  9. "year" => "2012",
  10. ]
  11. );

Methods

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the DependencyInjector container

public getDI ()

Returns the DependencyInjector container

public setBaseUri (mixed $baseUri)

Sets a prefix for all the URIs to be generated

  1. <?php
  2. $url->setBaseUri("/invo/");
  3. $url->setBaseUri("/invo/index.php/");

public setStaticBaseUri (mixed $staticBaseUri)

Sets a prefix for all static URLs generated

  1. <?php
  2. $url->setStaticBaseUri("/invo/");

public getBaseUri ()

Returns the prefix for all the generated urls. By default /

public getStaticBaseUri ()

Returns the prefix for all the generated static urls. By default /

public setBasePath (mixed $basePath)

Sets a base path for all the generated paths

  1. <?php
  2. $url->setBasePath("/var/www/htdocs/");

public getBasePath ()

Returns the base path

public get ([mixed $uri], [mixed $args], [mixed $local], [mixed $baseUri])

Generates a URL

  1. <?php
  2. // Generate a URL appending the URI to the base URI
  3. echo $url->get("products/edit/1");
  4. // Generate a URL for a predefined route
  5. echo $url->get(
  6. [
  7. "for" => "blog-post",
  8. "title" => "some-cool-stuff",
  9. "year" => "2015",
  10. ]
  11. );
  12. // Generate a URL with GET arguments (/show/products?id=1&name=Carrots)
  13. echo $url->get(
  14. "show/products",
  15. [
  16. "id" => 1,
  17. "name" => "Carrots",
  18. ]
  19. );
  20. // Generate an absolute URL by setting the third parameter as false.
  21. echo $url->get(
  22. "https://phalconphp.com/",
  23. null,
  24. false
  25. );

public getStatic ([mixed $uri])

Generates a URL for a static resource

  1. <?php
  2. // Generate a URL for a static resource
  3. echo $url->getStatic("img/logo.png");
  4. // Generate a URL for a static predefined route
  5. echo $url->getStatic(
  6. [
  7. "for" => "logo-cdn",
  8. ]
  9. );

public path ([mixed $path])

Generates a local path