Class Phalcon\Url
Source on GitHub
Namespace |
Phalcon |
|
Uses |
Phalcon\Di\DiInterface, Phalcon\Di\AbstractInjectionAware, Phalcon\Mvc\RouterInterface, Phalcon\Mvc\Router\RouteInterface, Phalcon\Url\Exception, Phalcon\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",
]
);
Властивості
/**
* @var null | string
*/
protected baseUri;
/**
* @var null | string
*/
protected basePath;
/**
* @var RouterInterface | null
*/
protected router;
/**
* @var null | string
*/
protected staticBaseUri;
Методи
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/");
Class Phalcon\Url\Exception
Source on GitHub
Namespace |
Phalcon\Url |
|
Extends |
\Phalcon\Exception |
Phalcon\Url\Exception
Exceptions thrown in Phalcon\Url will use this class
Interface Phalcon\Url\UrlInterface
Source on GitHub
Interface for Phalcon\Url\UrlInterface
Методи
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