Skip to content

Phalcon url

NOTE

All classes are prefixed with Phalcon

Url

Source on GitHub

  • Namespace

    • Phalcon\Mvc
  • Uses

    • Phalcon\Di\AbstractInjectionAware
    • Phalcon\Di\DiInterface
    • Phalcon\Mvc\RouterInterface
    • Phalcon\Mvc\Router\RouteInterface
    • Phalcon\Mvc\Url\Exception
    • Phalcon\Mvc\Url\UrlInterface
  • Extends

    AbstractInjectionAware

  • Implements

    • UrlInterface

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

// Generate a URL appending the URI to the base URI
echo $url->get("products/edit/1");

// Generate a URL for a predefined route
echo $url->get(
    [
        "for"   => "blog-post",
        "title" => "some-cool-stuff",
        "year"  => "2012",
    ]
);

Properties

/**
 * @var null | string
 */
protected $baseUri;

/**
 * @var null | string
 */
protected $basePath;

/**
 * @var RouterInterface | null
 */
protected $router;

/**
 * @var null | string
 */
protected $staticBaseUri;

Methods

public function __construct( RouterInterface $router = null );

public function get( mixed $uri = null, mixed $args = null, bool $local = null, mixed $baseUri = null ): string;
Generates a URL

// Generate a URL appending the URI to the base URI
echo $url->get("products/edit/1");

// Generate a URL for a predefined route
echo $url->get(
    [
        "for"   => "blog-post",
        "title" => "some-cool-stuff",
        "year"  => "2015",
    ]
);

// Generate a URL with GET arguments (/show/products?id=1&name=Carrots)
echo $url->get(
    "show/products",
    [
        "id"   => 1,
        "name" => "Carrots",
    ]
);

// Generate an absolute URL by setting the third parameter as false.
echo $url->get(
    "https://phalcon.io/",
    null,
    false
);

public function getBasePath(): string;
Returns the base path

public function getBaseUri(): string;
Returns the prefix for all the generated urls. By default /

public function getStatic( mixed $uri = null ): string;
Generates a URL for a static resource

// Generate a URL for a static resource
echo $url->getStatic("img/logo.png");

// Generate a URL for a static predefined route
echo $url->getStatic(
    [
        "for" => "logo-cdn",
    ]
);

public function getStaticBaseUri(): string;
Returns the prefix for all the generated static urls. By default /

public function path( string $path = null ): string;
Generates a local path

public function setBasePath( string $basePath ): UrlInterface;
Sets a base path for all the generated paths

$url->setBasePath("/var/www/htdocs/");

public function setBaseUri( string $baseUri ): UrlInterface;
Sets a prefix for all the URIs to be generated

$url->setBaseUri("/invo/");

$url->setBaseUri("/invo/index.php/");

public function setStaticBaseUri( string $staticBaseUri ): UrlInterface;
Sets a prefix for all static URLs generated

$url->setStaticBaseUri("/invo/");

Mvc\Url\Exception

Source on GitHub

  • Namespace

    • Phalcon\Mvc\Url
  • Uses

  • Extends

    \Exception

  • Implements

Phalcon\Mvc\Url\Exception

Exceptions thrown in Phalcon\Url will use this class

Mvc\Url\UrlInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Mvc\Url
  • Uses

  • Extends

  • Implements

Interface for Phalcon\Mvc\Url\UrlInterface

Methods

public function get( mixed $uri = null, mixed $args = null, bool $local = null ): string;
Generates a URL

public function getBasePath(): string;
Returns a base path

public function getBaseUri(): string;
Returns the prefix for all the generated urls. By default /

public function path( string $path = null ): string;
Generates a local path

public function setBasePath( string $basePath ): UrlInterface;
Sets a base paths for all the generated paths

public function setBaseUri( string $baseUri ): UrlInterface;
Sets a prefix to all the urls generated