URL
URL
Generate a URL relative to the application
This is the base method for generating URLs in your application. URLs generated directly from here are relative to the application base path. For URLs that are relative to the current controller see Controller::url()
Parameters are dynamic and depend on what you are trying to generate.
For examples see Generating URLs in the Hazaar MVC support documentation.
Properties
path
public string $path
params
public array $params
hash
public string $hash
basePath
public string $basePath
baseURL
public string $baseURL
rewriteURL
public bool $rewriteURL
aliases
public array $aliases
encoded
private bool $encoded
Methods
__construct
public __construct({Array})
__toString
Returns the string representation of the Url object.
public __toString({Array})
initialise
public initialise({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$config | Map |
toString
Write the URL as a string.
public toString({Array})
This method optionally takes an array to use to filter any placeholder parameters. Parameters support special placholder values that are prefixed with a '$', such as $name. The actual value is then taken from the array supplied to this method and replaced in the output. This allows a single URL object to be used multiple times and it's parameters changed
Example:
$url = new \Hazaar\Application\Url('controller', 'action', ['id' => '$id']);
echo $url->toString(['id' => 1234]);
This will output something like:
http://localhost/controller/action?id=1234
Parameters
Parameter | Type | Description |
---|---|---|
$values | array | override the default params with parameters in this array |
setParams
Set the HTTP request parameters on the URL.
public setParams({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$params | array | |
$merge | bool |
encode
Toggle encoding of the URL.
public encode({Array})
This will enable a feature that will encode the URL with a serialised base64 parameter list so that the path and parameters are obscured.
This is NOT a security feature and merely obscures the exact destination of the URL using standard reversible encoding functions that "normal" people won't understand. It can also make your URL look a bit 'tidier' or 'more professional' by making the parameters look weird. 😉
Parameters
Parameter | Type | Description |
---|---|---|
$encode | bool | Boolean to enable/disable encoding. Defaults to TRUE. |
getOrigin
Retrieves the origin of the URL.
public getOrigin({Array})
This method extracts the origin from the rendered URL by using a regular expression pattern. The origin is defined as the protocol and domain of the URL.
jsonSerialize
Returns the URL as a JSON serialized string.
public jsonSerialize({Array})
renderObject
Write the URL as a string.
private renderObject({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$params | array | override the default params with parameters in this array |
$encode | bool | encode the URL as a Hazaar MVC encoded query string URL |
Generated by Hazaar API Doc Generator