Backend\Classes\Controller

Extends:

Controller is a backend base controller class used by all Backend controllers

Public properties

public object $widget

Collection of WidgetBase objects used on this page.

public bool $suppressView

Prevents the automatic view display.

public string $pageTitle

Page title

public string $pageTitleTemplate

Page title template

public string $bodyClass

Body class property used for customising the layout on a controller basis.

public array $hiddenActions

Default methods which cannot be called as actions.

public array $vars

vars is a list of variables to pass to the page

public string $layout

layout to use for the view

public bool $suppressLayout

suppressLayout prevents the use of a layout

public string $assetPath

Specifies a path to the asset directory.

Show inherited public properties

Inherited public properties

Protected properties

protected object $user

Reference the logged in admin user.

protected array $params

Routed parameters.

protected string $action

Page action being called.

protected array $publicActions

Defines a collection of actions available without authentication.

protected array $requiredPermissions

Permissions required to view this page.

protected array $guarded

Controller specified methods which cannot be called as actions.

protected string|array $viewPath

viewPath specifies a path to the views directory

protected string $layoutPath

layoutPath specifies a path to the layout directory

protected array $assets

Collection of assets to display in the layout.

protected array $assetBundles

Collection of combined and prioritized assets.

protected string $configPath

Specifies a path to the config directory.

protected array $emitterSingleEventCollection

Collection of registered events to be fired once only.

protected array $emitterEventCollection

Collection of registered events.

protected array $emitterEventSorted

Sorted collection of events.

protected int $statusCode

Response status code

protected mixed $responseOverride

Override the standard controller response.

protected Symfony\Component\HttpFoundation\ResponseHeaderBag $responseHeaderBag

protected array $vueComponents

A list of registered Vue component classes

protected string $fatalError

Object used for storing a fatal error.

Show inherited protected properties

Inherited protected properties

Public methods

public void __construct()

Constructor.

public boolean actionExists(string $name, bool $internal=false)

actionExists is used internally to determines whether an action with the specified name exists.

  • Action must be a class public method.
  • Action name can not be prefixed with the underscore character.
  • Action name must be lowercase.
  • Action must not appear in hiddenActions.
Parameters
  • string $name - Specifies the action name.
  • bool $internal - Allow protected actions.

public void actionUrl($action=NULL, $path=NULL)

Returns a URL for this controller and supplied action.

Parameters
  • $action
  • $path

public void addCss($name, $attributes=array())

addCss includes a StyleSheet asset to the asset list

Parameters
  • $name
  • $attributes

public void addCssBundle($name, $attributes=array())

addCssBundle includes a CSS asset to the bundled combiner stream

Parameters
  • $name
  • $attributes

public void addJs($name, $attributes=array())

addJs includes a JavaScript asset to the asset list

Parameters
  • $name
  • $attributes

public void addJsBundle($name, $attributes=array())

addJsBundle includes a JS asset to the bundled combiner stream

Parameters
  • $name
  • $attributes

public void addRss($name, $attributes=array())

addRss adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

Parameters
  • $name
  • $attributes

public void addViewPath(string|array $path)

addViewPath prepends a path on the available view path locations

Parameters
  • string|array $path

public void beforeDisplay()

beforeDisplay is a method to override in your controller as a way to execute logic before each action executes. It is preferred over placing logic in the constructor

public self bindEvent($event, $callback, $priority=0)

Create a new event binding.

Parameters
  • $event
  • $callback
  • $priority

public self bindEventOnce($event, $callback)

Create a new event binding that fires once only

Parameters
  • $event
  • $callback

public void combineAssets($assets, $localPath='')

combineAssets runs asset paths through the Asset Combiner

Parameters
  • $assets
  • $localPath

public array fireEvent(string $event, array $params=array(), boolean $halt=false)

Fire an event and call the listeners.

Parameters
  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

public mixed fireSystemEvent(string $event, array $params=array(), boolean $halt=true)

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);
Parameters
  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

public string fireViewEvent(string $event, array $params=array())

Special event function used for extending within view files, allowing HTML to be injected multiple times.

For example:

<?= $this->fireViewEvent('backend.auth.extendSigninView') ?>
Parameters
  • string $event - Event name
  • array $params - Event parameters

public void flushAssets()

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.

public string getAjaxHandler()

Returns the AJAX handler for the current request, if available.

public string getAssetPath(string $fileName, string $assetPath=NULL)

Locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.

Parameters
  • string $fileName - File to load.
  • string $assetPath - Explicitly define an asset path.

public array getAssetPaths()

Returns an array of all registered asset paths.

public string getConfigPath(string $fileName, mixed $configPath=NULL)

Locates a file based on it's definition. If the file starts with the ~ symbol it will be returned in context of the application base path, otherwise it will be returned in context of the config path.

Parameters
  • string $fileName - File to load.
  • mixed $configPath - Explicitly define a config path.

public void getFatalError()

getFatalError returns error message

public void getId($suffix=NULL)

Returns a unique ID for the controller and route. Useful in creating HTML markup.

Parameters
  • $suffix

public void getPublicActions()

getPublicActions returns the controllers public actions

public Symfony\Component\HttpFoundation\ResponseHeaderBag|null getResponseHeaders()

Get the header response bag

public int getStatusCode()

Returns the status code for the current web response.

public string getViewPath(string $fileName, mixed $viewPath=NULL)

getViewPath locates a file based on its definition. The file name can be prefixed with a symbol (~|$) to return in context of the application or plugin base path, otherwise it will be returned in context of this object view path.

Parameters
  • string $fileName - File to load.
  • mixed $viewPath - Explicitly define a view path.

public array getViewPaths()

getViewPaths returns the active view path locations

public string guessConfigPath(string $suffix='')

Guess the package path for the called class.

Parameters
  • string $suffix - An extra path to attach to the end

public string guessConfigPathFrom(string $class, string $suffix='')

Guess the package path from a specified class.

Parameters
  • string $class - Class to guess path from.
  • string $suffix - An extra path to attach to the end

public string guessViewPath(string $suffix='', bool $isPublic=false)

guessViewPath guesses the package path for the called class

Parameters
  • string $suffix - An extra path to attach to the end
  • bool $isPublic - Returns public path instead of an absolute one

public string guessViewPathFrom(string $class, string $suffix='', bool $isPublic=false)

guessViewPathFrom guesses the package path from a specified class

Parameters
  • string $class - Class to guess path from.
  • string $suffix - An extra path to attach to the end
  • bool $isPublic - Returns public path instead of an absolute one

public void handleError($exception)

Sets standard page variables in the case of a controller error.

Parameters
  • $exception

public void hasAssetsDefined()

hasAssetsDefined returns true if assets any have been added

public boolean hasFatalError()

public boolean isBackendHintHidden(string $name)

Checks if a hint has been hidden by the user.

Parameters
  • string $name - Unique key name

public void isPublicAction($action)

isPublicAction returns true if the current action is public

Parameters
  • $action

public string makeAssets(string $type=NULL)

Outputs <link> and <script> tags to load assets previously added with addJs and addCss method calls

Parameters
  • string $type - Return an asset collection of a given type (css, rss, js) or null for all.

public object makeConfig(array $configFile=array(), array $requiredConfig=array())

Reads the contents of the supplied file and applies it to this object.

Parameters
  • array $configFile
  • array $requiredConfig

public stdClass makeConfigFromArray(array $configArray=array())

Makes a config object from an array, making the first level keys properties of a new object.

Parameters
  • array $configArray - Config array.

public string makeFileContents(string $filePath, array $extraParams=array())

makeFileContents includes a file path using output buffering

Parameters
  • string $filePath - Absolute path to the view file.
  • array $extraParams - Parameters that should be available to the view.

public Backend\Classes\FormWidgetBase makeFormWidget(string $class, mixed $fieldConfig=array(), array $widgetConfig=array())

Makes a form widget object with the supplied form field and widget configuration.

Parameters
  • string $class - Widget class name
  • mixed $fieldConfig - A field name, an array of config or a FormField object.
  • array $widgetConfig - An array of config.

public string makeHintPartial(string $name, string $partial=NULL, array $params=array())

Renders a hint partial, used for displaying informative information that can be hidden by the user. If you don't want to render a partial, you can supply content via the 'content' key of $params.

Parameters
  • string $name - Unique key name
  • string $partial - Reference to content (partial name)
  • array $params - Extra parameters

public mixed makeLayout(string $name=NULL, array $params=array(), bool $throwException=true)

makeLayout renders a layout

Parameters
  • string $name - Specifies the layout name. If this parameter is omitted, the $layout property will be used.
  • array $params - Parameter variables to pass to the view.
  • bool $throwException - Throw an exception if the layout is not found

public string makeLayoutPartial(string $partial, array $params=array())

makeLayoutPartial renders a layout partial

Parameters
  • string $partial - The view to load.
  • array $params - Parameter variables to pass to the view.

public mixed makePartial(string $partial, array $params=array(), bool $throwException=true)

makePartial renders a partial file contents located in the views folder

Parameters
  • string $partial - The view to load.
  • array $params - Parameter variables to pass to the view.
  • bool $throwException - Throw an exception if the partial is not found.

public mixed makeResponse(mixed $contents)

Prepares a response that considers overrides and custom responses.

Parameters
  • mixed $contents

public string makeView(string $view)

makeView loads a view with the name specified. Applies layout if its name is provided by the parent object. The view file must be situated in the views directory, and has the extension "htm"

Parameters
  • string $view - Specifies the view name, without extension. Eg: "index".

public string makeViewContent(string $contents, string $layout=NULL)

makeViewContent renders supplied contents inside a layout

Parameters
  • string $contents - The inner contents as a string.
  • string $layout - Specifies the layout name.

public Backend\Classes\WidgetBase makeWidget(string $class, array $widgetConfig=array())

Makes a widget object with the supplied configuration file.

Parameters
  • string $class - Widget class name
  • array $widgetConfig - An array of config.

public stdClass mergeConfig(mixed $configA, mixed $configB)

Merges two configuration sources, either prepared or not, and returns them as a single configuration object.

Parameters
  • mixed $configA
  • mixed $configB

public void onHideBackendHint()

Ajax handler to hide a backend hint, once hidden the partial will no longer display for the user.

public void outputVueComponentTemplates()

public void pageAction()

Invokes the current controller action without rendering a view, used by AJAX handler that may rely on the logic inside the action.

public void registerVueComponent(String $componentClassName)

Registers a Vue component to be loaded when the action view renders.

Parameters
  • String $componentClassName

public mixed run(string $action=NULL, array $params=array())

run executes the controller action

Parameters
  • string $action - The action name.
  • array $params - Routing parameters to pass to the action.

public $this setResponse(mixed $response)

Sets the response for the current page request cycle, this value takes priority over the standard response prepared by the controller.

Parameters
  • mixed $response - Response object or string

public $this setResponseCookie(Symfony\Component\HttpFoundation\Cookie|mixed $cookie)

Add a cookie to the response.

Parameters
  • Symfony\Component\HttpFoundation\Cookie|mixed $cookie

public $this setResponseHeader(string $key, array|string $values, bool $replace=true)

Set a header on the Response.

Parameters
  • string $key
  • array|string $values
  • bool $replace

public $this setStatusCode(int $code)

Sets the status code for the current web response.

Parameters
  • int $code - Status code

public self unbindEvent(string $event=NULL)

Destroys an event binding.

Parameters
  • string $event - Event to destroy

Show inherited public methods

Inherited public methods

Protected methods

protected void combineBundledAssets($type)

combineBundledAssets spins over every bundle definition and combines them to an asset

Parameters
  • $type

protected array emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

Parameters
  • string $eventName

protected void execAjaxHandlers()

execAjaxHandlers is used internally and unvokes a controller event handler and loads the supplied partials.

protected void execPageAction(string $actionName, array $parameters)

This method is used internally. Invokes the controller action and loads the corresponding view.

Parameters
  • string $actionName - Specifies a action name to execute.
  • array $parameters - A list of the action parameters.

protected void execPostbackHandler()

execPostbackHandler is used internally to execute a postback version of an AJAX handler.

protected string getAssetEntryBuildPath(array $asset)

Internal helper, attaches a build code to an asset path

Parameters
  • array $asset - Stored asset array

protected string getAssetScheme(string $asset)

Internal helper, get asset scheme

Parameters
  • string $asset - Specifies a path (URL) to the asset.

protected void getLocalPath($relativePath)

getLocalPath converts a relative path to a local path

Parameters
  • $relativePath

protected void handleViewException($e, $obLevel)

handleViewException handles a view exception

Parameters
  • $e
  • $obLevel

protected void isVueComponentRegistered($componentClassName)
Parameters
  • $componentClassName

protected void makeVueComponent($className)
Parameters
  • $className

protected void makeXsrfCookie()

makeXsrfCookie adds anti-CSRF cookie. Adds a cookie with a token for CSRF checks to the response.

protected void removeDuplicates()

Removes duplicate assets from the entire collection.

protected void renderAssetAttributes($type, $asset)

renderAssetAttributes takes an asset definition and returns the necessary HTML output

Parameters
  • $type
  • $asset

protected boolean runAjaxHandler($handler)

runAjaxHandler tries to find and run an AJAX handler in the page action. The method stops as soon as the handler is found.

Parameters
  • $handler

protected mixed runAjaxHandlerForWidget($widget, $handler)

Specific code for executing an AJAX handler for a widget. This will append the widget view paths to the controller and merge the vars.

Parameters
  • $widget
  • $handler

protected bool verifyCsrfToken()

verifyCsrfToken checks if the request requires verification first (not GET, HEAD, OPTIONS) and then the request data / headers for a valid CSRF token. Returns false if a valid token is not found. Override this method to disable the check.

protected bool verifyForceSecure()

verifyForceSecure checks if the back-end should force a secure protocol (HTTPS) enabled by config.

Show inherited protected methods

Inherited protected methods

  • protected boolean extendableIsAccessible(mixed $class, string $propertyName) - defined in October\Rain\Extension\Extendable. Checks if a property is accessible, property equivalent of is_callable().
  • protected void extensionExtractMethods(string $extensionName, object $extensionObject) - defined in October\Rain\Extension\Extendable. Extracts the available methods from a behavior and adds it to the.