Controller
The CMS controller class.
class Cms\Classes\Controller
The controller finds and serves requested pages.
Traits
Trait | Description |
---|---|
AssetMaker
|
Asset Maker Trait Adds asset based methods to a class |
EventEmitter
|
Adds system event related features to any class. |
ResponseMaker
|
Response Maker Trait Stores attributes the can be used to prepare a response from the server. |
SecurityController
|
Security Controller Trait Adds cross-site scripting protection methods to a controller based class |
Properties
public
$vars
:
array
= []
A list of variables to pass to the page.
protected $componentContext : Cms\Classes\ComponentBase
Object of the active component, used internally.
protected static $instance : self
Cache of self
protected $layout : Cms\Classes\Layout
A reference to the CMS layout template used by the page.
protected $layoutObj : Cms\Classes\CodeBase
A reference to the CMS layout code section object.
protected $page : Cms\Classes\Page
A reference to the CMS page template being processed.
protected $pageContents : string
Contains the rendered page contents string.
protected $pageObj : Cms\Classes\CodeBase
A reference to the CMS page code section object.
protected $partialStack : PartialStack
Component partial stack, used internally.
protected $router : Cms\Classes\Router
A reference to the Router object.
protected $theme : Cms\Classes\Theme
A reference to the CMS theme processed by the controller.
protected $twig : TwigEnvironment
Keeps the Twig environment object.
inherited public $assetPath : string
Specifies a path to the asset directory.
inherited
protected
$assets
:
array
= {"js":[],"css":[],"rss":[],"vite":[]}
Collection of assets to display in the layout.
inherited protected $orderFactor : integer
Ensures "first-come, first-served" applies to assets of the same ordering.
inherited
protected
$responseHeaderBag
:
Symfony\Component\HttpFoundation\ResponseHeaderBag
= null
inherited
protected
$responseOverride
:
mixed
= null
Override the standard controller response.
inherited
protected
$statusCode
:
int
= 200
Response status code
Methods
public
__construct (Cms\Classes\Theme $theme = null
)
: void
Creates the controller.
Property | Type | Description |
---|---|---|
$theme | Cms\Classes\Theme |
Specifies the CMS theme. If the theme is not specified, the current active theme used. |
public
addComponent (mixed $name, string $alias, array $properties, boolean $addToLayout = false
)
: ComponentBase | null
Adds a component to the page object.
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
Component class name or short name |
$alias | string |
string
Alias to give the component |
$properties | array |
array
Component properties |
$addToLayout | boolean |
boolean
Add to layout, instead of page |
Component object. Will return null
if a soft component is used but not found.
public
currentPageUrl (array $parameters = []
, boolean $routePersistence = true
)
: null | string
Looks up the current page URL with supplied parameters and route persistence.
Property | Type | Description |
---|---|---|
$parameters | array |
array
|
$routePersistence | boolean |
boolean
|
public findComponentByHandler (string $handler) : ComponentBase
Searches the layout and page components by an AJAX handler
Property | Type | Description |
---|---|---|
$handler | string |
string
|
The component object, if found
public findComponentByName (mixed $name) : ComponentBase
Searches the layout and page components by an alias
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
The component object, if found
public findComponentByPartial (string $partial) : ComponentBase | null
Searches the layout and page components by a partial file
Property | Type | Description |
---|---|---|
$partial | string |
string
|
The component object, if found
public getAjaxHandler () : string
Returns the AJAX handler for the current request, if available.
public static getController () : self | null
Returns an existing instance of the controller.
If the controller doesn't exists, returns null.
public getLayout () : Cms\Classes\Layout
Returns the CMS layout object being processed by the controller.
The object is not available on the early stages of the controller initialization.
Returns the Layout object or null.
public getLayoutObject () : Cms\Classes\CodeBase
Intended to be called from the page, returns the layout code base object.
public getLoader () : Cms\Twig\Loader
public getPage () : Cms\Classes\Page
Returns the CMS page object being processed by the controller.
The object is not available on the early stages of the controller initialization.
Returns the Page object or null.
public getPageObject () : Cms\Classes\CodeBase
Intended to be called from the layout, returns the page code base object.
public getRouter () : Cms\Classes\Router
public getTheme () : Cms\Classes\Theme
public getTwig () : TwigEnvironment
Returns the Twig environment.
public pageCycle ()
Invokes the current page cycle without rendering the page, used by AJAX handler that may rely on the logic inside the action.
public
pageUrl (mixed $name, array $parameters = []
, boolean $routePersistence = true
)
: string | null
Looks up the URL for a supplied page and returns it relative to the website root.
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
Specifies the Cms Page file name. |
$parameters | array |
array
Route parameters to consider in the URL. If boolean will be used as the value for $routePersistence |
$routePersistence | boolean |
boolean
By default the existing routing parameters will be included |
public
param (string $name, string $default = null
)
: string
Returns a routing parameter.
Property | Type | Description |
---|---|---|
$name | string |
string
Routing parameter name. |
$default | string |
string
Default to use if none is found. |
public
static
render (string $pageFile, array $parameters = []
, Cms\Classes\Theme $theme = null
)
: mixed
Renders a page in its entirety, including component initialization.
AJAX will be disabled for this process.
Property | Type | Description |
---|---|---|
$pageFile | string |
string
Specifies the CMS page file name to run. |
$parameters | array |
array
Routing parameters. |
$theme | Cms\Classes\Theme |
Theme object |
public
renderComponent (mixed $name, array $parameters = []
)
: string
Renders a component's default content, preserves the previous component context.
Property | Type | Description |
---|---|---|
$name | mixed |
mixed
|
$parameters | array |
array
|
Returns the component default contents.
public
renderContent (string $name, array $parameters = []
, boolean $throwException = true
)
: string | false
Renders a requested content file.
The framework uses this method internally.
Property | Type | Description |
---|---|---|
$name | string |
string
The content view to load. |
$parameters | array |
array
Parameter variables to pass to the view. |
$throwException | boolean |
boolean
Throw an exception if the content file is not found. |
Content file, or false if $throwException
is false.
public renderPage ()
Renders a requested page.
The framework uses this method internally.
public
renderPartial (string $name, array $parameters = []
, boolean $throwException = true
)
: mixed
Renders a requested partial.
The framework uses this method internally.
Property | Type | Description |
---|---|---|
$name | string |
string
The view to load. |
$parameters | array |
array
Parameter variables to pass to the view. |
$throwException | boolean |
boolean
Throw an exception if the partial is not found. |
Partial contents or false if not throwing an exception.
public
run (string $url = "\/"
)
: BaseResponse
Finds and serves the requested page.
If the page cannot be found, returns the page with the URL /404. If the /404 page doesn't exist, returns the system 404 page. If the parameter is null, the current URL used. If it is not provided then '/' is used
Property | Type | Description |
---|---|---|
$url | string |
string
Specifies the requested page URL. |
Returns the response to the provided URL
public
runPage (Cms\Classes\Page $page, boolean $useAjax = true
)
: mixed
Runs a page directly from its object and supplied parameters.
Property | Type | Description |
---|---|---|
$page | Cms\Classes\Page |
Specifies the CMS page to run. |
$useAjax | boolean |
boolean
|
public
setComponentContext (ComponentBase $component = null
)
: void
Set the component context manually, used by Components when calling renderPartial.
Property | Type | Description |
---|---|---|
$component | ComponentBase |
ComponentBase
|
public
themeUrl (mixed $url = null
)
: string
Converts supplied URL to a theme URL relative to the website root. If the URL provided is an array then the files will be combined.
Property | Type | Description |
---|---|---|
$url | mixed |
mixed
Specifies the theme-relative URL. If null, the theme path is returned. |
protected execAjaxHandlers () : mixed
Executes the page, layout, component and plugin AJAX handlers.
Returns the AJAX Response object or null.
protected execPageCycle ()
Executes the page life cycle.
Creates an object from the PHP sections of the page and it's layout, then executes their life cycle functions.
protected initComponents () : void
Initializes the components for the layout and page.
protected initCustomObjects () : void
Initializes the custom layout and page objects.
protected initTwigEnvironment () : void
Initializes the Twig environment and loader.
Registers the \Cms\Twig\Extension object with Twig.
protected isSoftComponent (string $label) : bool
Checks if component name has @.
Property | Type | Description |
---|---|---|
$label | string |
string
|
protected parseComponentLabel (string $label) : string
Removes prefixed '@' from soft component name
Property | Type | Description |
---|---|---|
$label | string |
string
|
protected postProcessResult (Cms\Classes\Page $page, string $url, string $content) : string
Post-processes page HTML code before it's sent to the client.
Note for pre-processing see cms.template.processTwigContent event.
Property | Type | Description |
---|---|---|
$page | Cms\Classes\Page |
Specifies the current CMS page. |
$url | string |
string
Specifies the current URL. |
$content | string |
string
The page markup to post-process. |
Returns the updated result string.
protected runAjaxHandler (string $handler) : bool
Tries to find and run an AJAX handler in the page, layout, components and plugins.
The method stops as soon as the handler is found.
Property | Type | Description |
---|---|---|
$handler | string |
string
name of the ajax handler |
Returns true if the handler was found. Returns false otherwise.
protected
setComponentPropertiesFromParams (ComponentBase $component, array $parameters = []
)
Sets component property values from partial parameters.
The property values should be defined as {{ param }}.
Property | Type | Description |
---|---|---|
$component | ComponentBase |
ComponentBase
The component object. |
$parameters | array |
array
Specifies the partial parameters. |
protected themeCombineAssets (array $url) : string
Generates a URL to the AssetCombiner for the provided array of assets
Property | Type | Description |
---|---|---|
$url | array |
array
|
inherited
public
addCss (string | array $name, array $attributes = []
)
: void
Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | string | array |
string | array
When an array of paths are provided they will be passed to the Asset Combiner |
$attributes | array |
array
When a string is provided it will be used as the 'build' attribute value |
inherited
public
addJs (string | array $name, array $attributes = []
)
: void
Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | string | array |
string | array
When an array of paths are provided they will be passed to the Asset Combiner |
$attributes | array |
array
When a string is provided it will be used as the 'build' attribute value |
inherited
public
addRss (string $name, array $attributes = []
)
: void
Adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | string |
string
|
$attributes | array |
array
|
inherited
public
addVite (array | string $entrypoints, ?string $package = null
)
: void
Adds Vite tags
Property | Type | Description |
---|---|---|
$entrypoints | array | string |
array | string
The list of entry points for Vite |
$package | ?string |
?string
The package name of the plugin or theme |
inherited
public
combineAssets (array $assets, string $localPath = ""
)
: string
Run the provided assets through the Asset Combiner
Property | Type | Description |
---|---|---|
$assets | array |
array
|
$localPath | string |
string
|
inherited
public
fireSystemEvent (string $event, array $params = []
, boolean $halt = true
)
: mixed
Fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.
For example:
$this->fireSystemEvent('backend.list.myEvent', ['my value']);
Is equivalent to:
$this->fireEvent('list.myEvent', ['myvalue'], true);
Event::fire('backend.list.myEvent', [$this, 'myvalue'], true);
Property | Type | Description |
---|---|---|
$event | string |
string
Event name |
$params | array |
array
Event parameters |
$halt | boolean |
boolean
Halt after first non-null result |
inherited
public
fireViewEvent (string $event, array $params = []
)
: string
Special event function used for extending within view files, allowing HTML to be injected multiple times.
For example:
= $this->fireViewEvent('backend.auth.extendSigninView') ?>Property | Type | Description |
---|---|---|
$event | string |
string
Event name |
$params | array |
array
Event parameters |
inherited public flushAssets () : void
Disables the use, and subequent broadcast, of assets. This is useful to call during an AJAX request to speed things up. This method works by specifically targeting the hasAssetsDefined method.
inherited
public
getAssetPath (string $fileName, $assetPath = null
)
: string
Returns the URL to the provided asset. If the provided fileName is a relative path without a leading slash it will be assumbed to be relative to the asset path.
Property | Type | Description |
---|---|---|
$fileName | string |
string
|
$assetPath | mixed |
mixed
|
inherited public getAssetPaths () : array
Returns an array of all registered asset paths.
Assets will be prioritized based on their defined ordering.
inherited public getResponseHeaders () : Symfony\Component\HttpFoundation\ResponseHeaderBag | null
Get the header response bag
inherited public getStatusCode () : int
Returns the status code for the current web response.
Status code
inherited public hasAssetsDefined () : bool
Returns true if assets any have been added.
inherited
public
makeAssets ($type = null
)
: string | null
Outputs <link>
and <script>
tags to load assets previously added
with addJs, addCss, & addRss method calls depending on the provided $type
Property | Type | Description |
---|---|---|
$type | mixed |
mixed
|
inherited public makeResponse (mixed $contents) : mixed
Prepares a response that considers overrides and custom responses.
Property | Type | Description |
---|---|---|
$contents | mixed |
mixed
|
inherited public orderAssets (array $assets) : array
Prioritize assets based on the given order.
Property | Type | Description |
---|---|---|
$assets | array |
array
|
inherited public setResponse (mixed $response) : $this
Sets the response for the current page request cycle, this value takes priority over the standard response prepared by the controller.
Property | Type | Description |
---|---|---|
$response | mixed |
mixed
Response object or string |
inherited public setResponseCookie (Symfony\Component\HttpFoundation\Cookie | mixed $cookie) : $this
Add a cookie to the response.
Property | Type | Description |
---|---|---|
$cookie | Symfony\Component\HttpFoundation\Cookie | mixed |
Symfony\Component\HttpFoundation\Cookie | mixed
|
inherited
public
setResponseHeader (string $key, array | string $values, boolean $replace = true
)
: $this
Set a header on the Response.
Property | Type | Description |
---|---|---|
$key | string |
string
|
$values | array | string |
array | string
|
$replace | boolean |
boolean
|
inherited public setStatusCode (int $code) : $this
Sets the status code for the current web response.
Property | Type | Description |
---|---|---|
$code | int |
int
Status code |
inherited protected addAsset (string $type, string $path, array $attributes) : void
Adds the provided asset to the internal asset collections
Property | Type | Description |
---|---|---|
$type | string |
string
|
$path | string |
string
|
$attributes | array |
array
|
inherited protected getAssetEntryBuildPath (array $asset) : string
Internal helper, attaches a build code to an asset path
Property | Type | Description |
---|---|---|
$asset | array |
array
|
inherited protected getAssetScheme (string $asset) : string
Internal helper, get asset scheme
Property | Type | Description |
---|---|---|
$asset | string |
string
|
inherited protected getLocalPath (string | null $relativePath) : string
Property | Type | Description |
---|---|---|
$relativePath | string | null |
string | null
|
inherited protected makeXsrfCookie () : Symfony\Component\HttpFoundation\Cookie
Adds anti-CSRF cookie.
Adds a cookie with a token for CSRF checks to the response.
inherited protected removeDuplicates () : void
Removes duplicate assets from the entire collection.
inherited protected verifyCsrfToken () : bool
Checks the request data / headers for a valid CSRF token.
Returns false if a valid token is not found or cms.enableCsrfProtection is set to false
inherited protected verifyForceSecure () : bool
Checks if the back-end should force a secure protocol (HTTPS) enabled by config.