Documentation

UrlMaker

URL Maker Trait

Useful in models for generating a "url" attribute, automatically linked to a primary component used in the active theme. For example:

use \Cms\Traits\UrlMaker;

protected $urlComponentName = 'blogPost';

When declared in a model, the above will result in $model->url magically linking to the component that declares isPrimary = 1 in configuration.

[blogPost] isPrimary = "1"

The parameters passed to the component are supplied when overriding the method getUrlParams also within the model.

public function getUrlParams() { return [ 'id' => $this->id, 'hash' => $this->hash, ]; }

Tags
author

Alexey Bobkov, Samuel Georges

Table of Contents

$url  : string
$urlPageName  : string
getUrlAttribute()  : string
Mutator for the "url" attribute. Returns the URL detected by the component.
getUrlPageName()  : string
Locates the page name where the detected component is found. This method uses the Cache service to improve performance.
resetUrlComponent()  : void
Changes the component used for generating the URLs dynamically.
setUrlAttribute()  : void
Explicitly set the URL for this model.
setUrlPageName()  : void
Explicitly set the CMS Page to link to.
makeUrl()  : string
Generates a real URL based on the page, detected by the primary component.

Properties

$urlPageName

protected static string $urlPageName

Page where detected component is found.

Methods

getUrlAttribute()

Mutator for the "url" attribute. Returns the URL detected by the component.

public getUrlAttribute() : string
Return values
string

getUrlPageName()

Locates the page name where the detected component is found. This method uses the Cache service to improve performance.

public getUrlPageName() : string
Return values
string

resetUrlComponent()

Changes the component used for generating the URLs dynamically.

public resetUrlComponent(string $name[, string $property = null ]) : void
Parameters
$name : string
$property : string = null
Return values
void

setUrlAttribute()

Explicitly set the URL for this model.

public setUrlAttribute(string $value) : void
Parameters
$value : string
Return values
void

setUrlPageName()

Explicitly set the CMS Page to link to.

public setUrlPageName(string $pageName) : void
Parameters
$pageName : string
Return values
void

makeUrl()

Generates a real URL based on the page, detected by the primary component.

protected makeUrl() : string

The CMS Controller is used for this process passing the declared params.

Return values
string

Search results