Backend\Classes\Controller

Source: ~/modules/backend/classes/Controller.php

Extends:

The Backend base controller class, used by Backend controllers. The base controller services back end pages.

Public properties

public array $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

A list of variables to pass to the page.

public string $layout

Layout to use for the view.

public bool $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 int $statusCode

Response status code

protected string|array $viewPath

Specifies a path to the views directory.

protected string $layoutPath

Specifies a path to the layout directory.

protected array $assets

Collection of assets to display in the layout.

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 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)

This method is used internally. 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.

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(string $name, array $attributes=array())

Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

Parameters
  • string $name - Specifies a path (URL) to the script.
  • array $attributes - Adds extra HTML attributes to the asset link.

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

Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

Parameters
  • string $name - Specifies a path (URL) to the script.
  • array $attributes - Adds extra HTML attributes to the asset link.

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

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

Parameters
  • string $name - Specifies a path (URL) to the RSS channel
  • array $attributes - Adds extra HTML attributes to the asset link.

public void addViewPath(string|array $path)

Prepends a path on the available view path locations.

Parameters
  • string|array $path

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 string combineAssets(array $assets, string $localPath='')

Run the provided assets through the Asset Combiner

Parameters
  • array $assets - Collection of assets
  • string $localPath - Prefix all assets with this path (optional)

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 getId($suffix=NULL)

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

Parameters
  • $suffix

public void getPublicActions()

Returns the controllers public actions.

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

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()

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)

Guess 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)

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
  • 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 bool hasAssetsDefined()

Returns true if assets any have been added.

public boolean isBackendHintHidden(string $name)

Checks if a hint has been hidden by the user.

Parameters
  • string $name - Unique key name

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 array|stdClass 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 a new object. Property values are converted to camelCase and are not set if one already exists.

Parameters
  • array $configArray - Config array.

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

Includes a file path using output buffering. Ensures that vars are available.

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)

Render 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())

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)

Render 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 string makeView(string $view)

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)

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 pageAction()

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

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

Execute the controller action.

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

public void 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 array emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

Parameters
  • string $eventName

protected void execAjaxHandlers()

This method is used internally. Invokes 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 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 handleViewException(Exception $e, int $obLevel)

Handle a view exception.

Parameters
  • Exception $e
  • int $obLevel

protected void removeDuplicates()

Removes duplicate assets from the entire collection.

protected boolean runAjaxHandler($handler)

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()

Checks 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()

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_callabe().
  • 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.