HumHub Documentation (unofficial)

Module extends Module
in package

Dashboard Module

Tags
author

Luke

Table of Contents

Constants

EVENT_AFTER_ACTION  = 'afterAction'
EVENT_BEFORE_ACTION  = 'beforeAction'
STREAM_AUTO_INCLUDE_PROFILE_POSTS_ADMIN_ONLY  = 'admin'
STREAM_AUTO_INCLUDE_PROFILE_POSTS_ALWAYS  = 'all'
Possible options to include profile posts into the dashboard stream

Properties

$aliases  : array<string|int, mixed>
$autoIncludeProfilePosts  : string
$basePath  : string
$behaviors  : array<string|int, Behavior>
$components  : array<string|int, mixed>
$controllerMap  : array<string|int, mixed>
$controllerNamespace  : mixed
$controllerPath  : string
$defaultRoute  : string
$description  : string
$guestFilterClass  : string
Dashboard stream query filter class used for guest users
$hideActivitySidebarWidget  : bool
$id  : string
$isEnabled  : bool
$keywords  : array<string|int, mixed>
$layout  : string|bool|null
$layoutPath  : string
$memberFilterClass  : string
Dashboard stream query filter class used for members of the network
$module  : Module|null
$modules  : array<string|int, mixed>
$name  : string
$params  : array<string|int, mixed>
$resourcesPath  : string
$settings  : SettingsManager
$uniqueId  : string
$version  : string
$viewPath  : string
$_basePath  : string
$_behaviors  : array<string|int, Behavior>|null
$_components  : array<string|int, mixed>
$_controllerPath  : string
$_definitions  : array<string|int, mixed>
$_events  : array<string|int, mixed>
$_eventWildcards  : array<string|int, mixed>
$_layoutPath  : string
$_moduleInfo  : array<string|int, mixed>|null
$_modules  : array<string|int, mixed>
$_version  : string|callable|null
$_viewPath  : string

Methods

__call()  : mixed
Calls the named method which is not a class method.
__clone()  : mixed
This method is called after the object is created by cloning an existing one.
__construct()  : mixed
Constructor.
__get()  : mixed
Getter magic method.
__isset()  : bool
Checks if a property value is null.
__set()  : mixed
Sets the value of a component property.
__unset()  : mixed
Sets a component property to be null.
afterAction()  : mixed
This method is invoked right after an action within this module is executed.
afterUpdate()  : mixed
Called right after the module update.
attachBehavior()  : Behavior
Attaches a behavior to this component.
attachBehaviors()  : mixed
Attaches a list of behaviors to the component.
beforeAction()  : bool
This method is invoked right before an action within this module is executed.
beforeUpdate()  : bool
Called right before the module is updated.
behaviors()  : array<string|int, mixed>
Returns a list of behaviors that this component should behave as.
canGetProperty()  : bool
Returns a value indicating whether a property can be read.
canSetProperty()  : bool
Returns a value indicating whether a property can be set.
className()  : string
Returns the fully qualified name of this class.
clear()  : mixed
Removes the component from the locator.
createController()  : array<string|int, mixed>|bool
Creates a controller instance based on the given route.
createControllerByID()  : Controller|null
Creates a controller based on the given controller ID.
detachBehavior()  : Behavior|null
Detaches a behavior from the component.
detachBehaviors()  : mixed
Detaches all behaviors from the component.
disable()  : bool|null
Disables a module
enable()  : bool|null
Enables this module
ensureBehaviors()  : mixed
Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
get()  : object|null
Returns the component instance with the specified ID.
getActivityClasses()  : array<string|int, mixed>
Returns a list of activity class names this modules provides.
getAssetClasses()  : array<string|int, mixed>
Returns a list of asset class names this modules provides.
getAssetPath()  : mixed
getAssetsUrl()  : string
Get Assets Url
getBasePath()  : string
Returns the root directory of the module.
getBehavior()  : Behavior|null
Returns the named behavior object.
getBehaviors()  : array<string|int, Behavior>
Returns all behaviors attached to this component.
getComponents()  : array<string|int, mixed>
Returns the list of the component definitions or the loaded component instances.
getConfigUrl()  : string
URL to the module's configuration action
getControllerPath()  : string
Returns the directory that contains the controller classes according to [[controllerNamespace]].
getDescription()  : string
Returns the module's description provided by module.json file
getImage()  : string
Returns image url for this module Place your modules image in <resourcesPath>/module_image.png
getInstance()  : static|null
Returns the currently requested instance of this module class.
getIsActivated()  : bool
getIsEnabled()  : bool
Check this module is enabled
getKeywords()  : array<string|int, mixed>
Returns module's keywords provided by module.json file
getLayoutPath()  : string
Returns the directory that contains layout view files for this module.
getMigrationService()  : MigrationService
getModule()  : Module|null
Retrieves the child module of the specified ID.
getModuleInstance()  : static
getModules()  : array<string|int, mixed>
Returns the sub-modules in this module.
getName()  : string
Returns the module's name provided by module.json file
getNotifications()  : array<string|int, mixed>
Returns a list of notification classes this module provides.
getOnlineModule()  : Module|null
getPermissions()  : array<string|int, mixed>
Returns a list of permission objects this module provides.
getPublishedUrl()  : string
Returns the url of an asset file and publishes all module assets if the file is not published yet.
getUniqueId()  : string
Returns an ID that uniquely identifies this module among all modules within the current application.
getVersion()  : string
Returns the module's version number provided by module.json file
getViewPath()  : string
Returns the directory that contains the view files for this module.
has()  : bool
Returns a value indicating whether the locator has the specified component definition or has instantiated the component.
hasEventHandlers()  : bool
Returns a value indicating whether there is any handler attached to the named event.
hasMethod()  : bool
Returns a value indicating whether a method is defined.
hasModule()  : bool
Checks whether the child module of the specified ID exists.
hasNotifications()  : bool
Determines whether the module has notification classes or not
hasProperty()  : bool
Returns a value indicating whether a property is defined for this component.
init()  : mixed
Initializes the module.
isPublished()  : string
Checks if a specific asset file has already been published
migrate()  : mixed
Execute all not applied module migrations
off()  : bool
Detaches an existing event handler from this component.
on()  : mixed
Attaches an event handler to an event.
publishAssets()  : array<string|int, mixed>
Publishes the basePath/resourcesPath (assets) module directory if existing.
runAction()  : mixed
Runs a controller action specified by a route.
set()  : mixed
Registers a component definition with this locator.
setAliases()  : mixed
Defines path aliases.
setBasePath()  : mixed
Sets the root directory of the module.
setComponents()  : mixed
Registers a set of component definitions in this locator.
setControllerPath()  : mixed
Sets the directory that contains the controller classes.
setInstance()  : mixed
Sets the currently requested instance of this module class.
setLayoutPath()  : mixed
Sets the directory that contains the layout files.
setModule()  : mixed
Adds a sub-module to this module.
setModules()  : mixed
Registers sub-modules in the current module.
setVersion()  : mixed
Sets current module version.
setViewPath()  : mixed
Sets the directory that contains the view files.
trigger()  : mixed
Triggers an event.
update()  : mixed
This method is called after an update is performed.
defaultVersion()  : string
Returns default module version.
getModuleInfo()  : array<string|int, mixed>
Reads module.json which contains basic module information and returns it as array
attachBehaviorInternal()  : Behavior
Attaches a behavior to this component.
hasAssets()  : bool
Determines whether or not this module has an asset directory.
isIncorrectClassNameOrPrefix()  : bool
Checks if class name or prefix is incorrect

Constants

EVENT_AFTER_ACTION

public mixed EVENT_AFTER_ACTION = 'afterAction'
Tags
event

ActionEvent an event raised after executing a controller action.

EVENT_BEFORE_ACTION

public mixed EVENT_BEFORE_ACTION = 'beforeAction'
Tags
event

ActionEvent an event raised before executing a controller action. You may set [[ActionEvent::isValid]] to be false to cancel the action execution.

STREAM_AUTO_INCLUDE_PROFILE_POSTS_ADMIN_ONLY

public mixed STREAM_AUTO_INCLUDE_PROFILE_POSTS_ADMIN_ONLY = 'admin'

STREAM_AUTO_INCLUDE_PROFILE_POSTS_ALWAYS

Possible options to include profile posts into the dashboard stream

public mixed STREAM_AUTO_INCLUDE_PROFILE_POSTS_ALWAYS = 'all'

Default/Null: Default, only include profile posts when user is followed Always: Always include all user profile posts into dashboards Admin Only: For admin users, always include all profile posts (without following)

Properties

$aliases write-only

public array<string|int, mixed> $aliases

List of path aliases to be defined. The array keys are alias names (must start with @) and the array values are the corresponding paths or aliases. See [[setAliases()]] for an example.

$autoIncludeProfilePosts

public string $autoIncludeProfilePosts = null

profile

Tags
since
1.2.4

$basePath

public string $basePath

The root directory of the module.

$behaviors read-only

public array<string|int, Behavior> $behaviors

List of behaviors attached to this component.

$components

public array<string|int, mixed> $components

The list of the component definitions or the loaded component instances (ID => definition or instance).

$controllerMap

public array<string|int, mixed> $controllerMap = []

mapping from controller ID to controller configurations. Each name-value pair specifies the configuration of a single controller. A controller configuration can be either a string or an array. If the former, the string should be the fully qualified class name of the controller. If the latter, the array must contain a class element which specifies the controller's fully qualified class name, and the rest of the name-value pairs in the array are used to initialize the corresponding controller properties. For example,

[
  'account' => 'app\controllers\UserController',
  'article' => [
     'class' => 'app\controllers\PostController',
     'pageTitle' => 'something new',
  ],
]

$controllerNamespace

public mixed $controllerNamespace = 'humhub\modules\dashboard\controllers'
Tags
inheritdocs

$controllerPath

public string $controllerPath

The directory that contains the controller classes.

$defaultRoute

public string $defaultRoute = 'default'

the default route of this module. Defaults to default. The route may consist of child module ID, controller ID, and/or action ID. For example, help, post/create, admin/post/create. If action ID is not given, it will take the default value as specified in [[Controller::defaultAction]].

$description read-only

public string $description

$guestFilterClass

Dashboard stream query filter class used for guest users

public string $guestFilterClass = \humhub\modules\dashboard\stream\filters\DashboardGuestStreamFilter::class
Tags
since
1.8

$hideActivitySidebarWidget

public bool $hideActivitySidebarWidget = false

hides the activities sidebar widget

Tags
since
1.3.14

$id

public string $id

an ID that uniquely identifies this module among other modules which have the same [[module|parent]].

$isEnabled read-only

public bool $isEnabled

$keywords read-only

public array<string|int, mixed> $keywords

$layout

public string|bool|null $layout

the layout that should be applied for views within this module. This refers to a view name relative to [[layoutPath]]. If this is not set, it means the layout value of the [[module|parent module]] will be taken. If this is false, layout will be disabled within this module.

$layoutPath

public string $layoutPath

The root directory of layout files. Defaults to "[[viewPath]]/layouts".

$memberFilterClass

Dashboard stream query filter class used for members of the network

public string $memberFilterClass = \humhub\modules\dashboard\stream\filters\DashboardMemberStreamFilter::class
Tags
since
1.8

$module

public Module|null $module

the parent module of this module. null if this module does not have a parent.

$modules

public array<string|int, mixed> $modules

The modules (indexed by their IDs).

$name read-only

public string $name

$params

public array<string|int, mixed> $params = []

custom module parameters (name => value).

$resourcesPath

public string $resourcesPath = 'assets'

The path for module resources (images, javascripts) Also module related assets like README.md and module_image.png should be placed here.

$uniqueId read-only

public string $uniqueId

The unique ID of the module.

$version

public string $version

The version of this module. Note that the type of this property differs in getter and setter. See [[getVersion()]] and [[setVersion()]] for details.

$viewPath

public string $viewPath

The root directory of view files. Defaults to "[[basePath]]/views".

$_basePath

private string $_basePath

the root directory of the module.

$_behaviors

private array<string|int, Behavior>|null $_behaviors

the attached behaviors (behavior name => behavior). This is null when not initialized.

$_components

private array<string|int, mixed> $_components = []

shared component instances indexed by their IDs

$_controllerPath

private string $_controllerPath

The root directory that contains the controller classes for this module.

$_definitions

private array<string|int, mixed> $_definitions = []

component definitions indexed by their IDs

$_events

private array<string|int, mixed> $_events = []

the attached event handlers (event name => handlers)

$_eventWildcards

private array<string|int, mixed> $_eventWildcards = []

the event handlers attached for wildcard patterns (event name wildcard => handlers)

Tags
since
2.0.14

$_layoutPath

private string $_layoutPath

the root directory that contains layout view files for this module.

$_moduleInfo

private array<string|int, mixed>|null $_moduleInfo = null

the loaded module.json info file

$_modules

private array<string|int, mixed> $_modules = []

child modules of this module

$_version

private string|callable|null $_version

the version of this module. Version can be specified as a PHP callback, which can accept module instance as an argument and should return the actual version. For example:

function (Module $module) {
    //return string|int
}

If not set, [[defaultVersion()]] will be used to determine actual value.

Tags
since
2.0.11

$_viewPath

private string $_viewPath

the root directory that contains view files for this module

Methods

__call()

Calls the named method which is not a class method.

public __call(string $name, array<string|int, mixed> $params) : mixed

This method will check if any attached behavior has the named method and will execute it if available.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

Parameters
$name : string

the method name

$params : array<string|int, mixed>

method parameters

Tags
throws
UnknownMethodException

when calling unknown method

Return values
mixed

the method return value

__clone()

This method is called after the object is created by cloning an existing one.

public __clone() : mixed

It removes all behaviors because they are attached to the old object.

__construct()

Constructor.

public __construct(string $id[, Module|null $parent = null ][, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$id : string

the ID of this module.

$parent : Module|null = null

the parent module (if any).

$config : array<string|int, mixed> = []

name-value pairs that will be used to initialize the object properties.

__get()

Getter magic method.

public __get(string $name) : mixed

This method is overridden to support accessing components like reading properties.

Parameters
$name : string

component or property name

Return values
mixed

the named property value

__isset()

Checks if a property value is null.

public __isset(string $name) : bool

This method overrides the parent implementation by checking if the named component is loaded.

Parameters
$name : string

the property name or the event name

Return values
bool

whether the property value is null

__set()

Sets the value of a component property.

public __set(string $name, mixed $value) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value
  • an event in the format of "on xyz": attach the handler to the event "xyz"
  • a behavior in the format of "as xyz": attach the behavior named as "xyz"
  • a property of a behavior: set the behavior property value

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.

Parameters
$name : string

the property name or the event name

$value : mixed

the property value

Tags
throws
UnknownPropertyException

if the property is not defined

throws
InvalidCallException

if the property is read-only.

see
__get()

__unset()

Sets a component property to be null.

public __unset(string $name) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value to be null
  • a property of a behavior: set the property value to be null

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($component->property).

Parameters
$name : string

the property name

Tags
throws
InvalidCallException

if the property is read only.

see
https://www.php.net/manual/en/function.unset.php

afterAction()

This method is invoked right after an action within this module is executed.

public afterAction(Action $action, mixed $result) : mixed

The method will trigger the [[EVENT_AFTER_ACTION]] event. The return value of the method will be used as the action return value.

If you override this method, your code should look like the following:

public function afterAction($action, $result)
{
    $result = parent::afterAction($action, $result);
    // your custom code here
    return $result;
}
Parameters
$action : Action

the action just executed.

$result : mixed

the action return result.

Return values
mixed

the processed action result.

afterUpdate()

Called right after the module update.

public afterUpdate() : mixed
Tags
deprecated

attachBehavior()

Attaches a behavior to this component.

public attachBehavior(string $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior

This method will create the behavior object based on the given configuration. After that, the behavior object will be attached to this component by calling the [[Behavior::attach()]] method.

Parameters
$name : string

the name of the behavior.

$behavior : string|array<string|int, mixed>|Behavior

the behavior configuration. This can be one of the following:

  • a [[Behavior]] object
  • a string specifying the behavior class
  • an object configuration array that will be passed to [[Yii::createObject()]] to create the behavior object.
Tags
see
detachBehavior()
Return values
Behavior

the behavior object

attachBehaviors()

Attaches a list of behaviors to the component.

public attachBehaviors(array<string|int, mixed> $behaviors) : mixed

Each behavior is indexed by its name and should be a [[Behavior]] object, a string specifying the behavior class, or an configuration array for creating the behavior.

Parameters
$behaviors : array<string|int, mixed>

list of behaviors to be attached to the component

Tags
see
attachBehavior()

beforeAction()

This method is invoked right before an action within this module is executed.

public beforeAction(Action $action) : bool

The method will trigger the [[EVENT_BEFORE_ACTION]] event. The return value of the method will determine whether the action should continue to run.

In case the action should not run, the request should be handled inside of the beforeAction code by either providing the necessary output or redirecting the request. Otherwise the response will be empty.

If you override this method, your code should look like the following:

public function beforeAction($action)
{
    if (!parent::beforeAction($action)) {
        return false;
    }

    // your custom code here

    return true; // or false to not run the action
}
Parameters
$action : Action

the action to be executed.

Return values
bool

whether the action should continue to be executed.

beforeUpdate()

Called right before the module is updated.

public beforeUpdate() : bool

The update will cancel if this function does return false;

Tags
deprecated
Return values
bool

behaviors()

Returns a list of behaviors that this component should behave as.

public behaviors() : array<string|int, mixed>

Child classes may override this method to specify the behaviors they want to behave as.

The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

Note that a behavior class must extend from [[Behavior]]. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using [[getBehavior()]] or be detached using [[detachBehavior()]]. Anonymous behaviors can not be retrieved or detached.

Behaviors declared in this method will be attached to the component automatically (on demand).

Return values
array<string|int, mixed>

the behavior configurations.

canGetProperty()

Returns a value indicating whether a property can be read.

public canGetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property can be read if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a readable property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canSetProperty()
Return values
bool

whether the property can be read

canSetProperty()

Returns a value indicating whether a property can be set.

public canSetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property can be written if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a writable property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canGetProperty()
Return values
bool

whether the property can be written

className()

Returns the fully qualified name of this class.

public static className() : string
Tags
deprecated

since 2.0.14. On PHP >=5.5, use ::class instead.

Return values
string

the fully qualified name of this class.

clear()

Removes the component from the locator.

public clear(string $id) : mixed
Parameters
$id : string

the component ID

createController()

Creates a controller instance based on the given route.

public createController(string $route) : array<string|int, mixed>|bool

The route should be relative to this module. The method implements the following algorithm to resolve the given route:

  1. If the route is empty, use [[defaultRoute]];
  2. If the first segment of the route is found in [[controllerMap]], create a controller based on the corresponding configuration found in [[controllerMap]];
  3. If the first segment of the route is a valid module ID as declared in [[modules]], call the module's createController() with the rest part of the route;
  4. The given route is in the format of abc/def/xyz. Try either abc\DefController or abc\def\XyzController class within the [[controllerNamespace|controller namespace]].

If any of the above steps resolves into a controller, it is returned together with the rest part of the route which will be treated as the action ID. Otherwise, false will be returned.

Parameters
$route : string

the route consisting of module, controller and action IDs.

Tags
throws
InvalidConfigException

if the controller class and its file do not match.

Return values
array<string|int, mixed>|bool

If the controller is created successfully, it will be returned together with the requested action ID. Otherwise false will be returned.

createControllerByID()

Creates a controller based on the given controller ID.

public createControllerByID(string $id) : Controller|null

The controller ID is relative to this module. The controller class should be namespaced under [[controllerNamespace]].

Note that this method does not check [[modules]] or [[controllerMap]].

Parameters
$id : string

the controller ID.

Tags
throws
InvalidConfigException

if the controller class and its file name do not match. This exception is only thrown when in debug mode.

Return values
Controller|null

the newly created controller instance, or null if the controller ID is invalid.

detachBehavior()

Detaches a behavior from the component.

public detachBehavior(string $name) : Behavior|null

The behavior's [[Behavior::detach()]] method will be invoked.

Parameters
$name : string

the behavior's name.

Return values
Behavior|null

the detached behavior. Null if the behavior does not exist.

detachBehaviors()

Detaches all behaviors from the component.

public detachBehaviors() : mixed

disable()

Disables a module

public disable() : bool|null

This should delete all data created by this module. When overriding this method, make sure to invoke call parent::disable() AFTER your implementation as

public function disable()
{
    // custom disable logic
    parent::disable();
}
Tags
throws
InvalidConfigException
throws
StaleObjectException
throws
Throwable
Return values
bool|null

Result uninstall-migration or null if beforeDisable() returned false (since v1.16)

enable()

Enables this module

public enable() : bool|null
Tags
throws
InvalidConfigException
Return values
bool|null

Result of migration or null if beforeEnable() returned false (since v1.16)

ensureBehaviors()

Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.

public ensureBehaviors() : mixed

get()

Returns the component instance with the specified ID.

public get(mixed $id[, mixed $throwException = true ]) : object|null

Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. The parent module may be the application.

Parameters
$id : mixed

component ID (e.g. db).

$throwException : mixed = true

whether to throw an exception if $id is not registered with the locator before.

Return values
object|null

the component of the specified ID. If $throwException is false and $id is not registered before, null will be returned.

getActivityClasses()

Returns a list of activity class names this modules provides.

public getActivityClasses() : array<string|int, mixed>
Tags
since
1.2
Return values
array<string|int, mixed>

list of activity class names

getAssetClasses()

Returns a list of asset class names this modules provides.

public getAssetClasses() : array<string|int, mixed>
Tags
since
1.2.8
Return values
array<string|int, mixed>

list of asset class names

getAssetPath()

public getAssetPath() : mixed

getAssetsUrl()

Get Assets Url

public getAssetsUrl() : string
Return values
string

Image Url

getBasePath()

Returns the root directory of the module.

public getBasePath() : string

It defaults to the directory containing the module class file.

Return values
string

the root directory of the module.

getBehavior()

Returns the named behavior object.

public getBehavior(string $name) : Behavior|null
Parameters
$name : string

the behavior name

Return values
Behavior|null

the behavior object, or null if the behavior does not exist

getBehaviors()

Returns all behaviors attached to this component.

public getBehaviors() : array<string|int, Behavior>
Return values
array<string|int, Behavior>

list of behaviors attached to this component

getComponents()

Returns the list of the component definitions or the loaded component instances.

public getComponents([bool $returnDefinitions = true ]) : array<string|int, mixed>
Parameters
$returnDefinitions : bool = true

whether to return component definitions instead of the loaded component instances.

Return values
array<string|int, mixed>

the list of the component definitions or the loaded component instances (ID => definition or instance).

getConfigUrl()

URL to the module's configuration action

public getConfigUrl() : string
Return values
string

the configuration url

getControllerPath()

Returns the directory that contains the controller classes according to [[controllerNamespace]].

public getControllerPath() : string

Note that in order for this method to return a value, you must define an alias for the root namespace of [[controllerNamespace]].

Tags
throws
InvalidArgumentException

if there is no alias defined for the root namespace of [[controllerNamespace]].

Return values
string

the directory that contains the controller classes.

getDescription()

Returns the module's description provided by module.json file

public getDescription() : string
Return values
string

Description

getImage()

Returns image url for this module Place your modules image in <resourcesPath>/module_image.png

public getImage() : string
Return values
string

Image Url

getInstance()

Returns the currently requested instance of this module class.

public static getInstance() : static|null

If the module class is not currently requested, null will be returned. This method is provided so that you access the module instance from anywhere within the module.

Return values
static|null

the currently requested instance of this module class, or null if the module class is not requested.

getIsActivated()

public getIsActivated() : bool
Tags
see
static::getIsEnabled()
deprecated

since 1.16; use static::getIsEnabled() instead.

noinspection

PhpUnused

Return values
bool

getIsEnabled()

Check this module is enabled

public getIsEnabled() : bool
Return values
bool

getKeywords()

Returns module's keywords provided by module.json file

public getKeywords() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of keywords

getLayoutPath()

Returns the directory that contains layout view files for this module.

public getLayoutPath() : string
Return values
string

the root directory of layout files. Defaults to "[[viewPath]]/layouts".

getModule()

Retrieves the child module of the specified ID.

public getModule(string $id[, bool $load = true ]) : Module|null

This method supports retrieving both child modules and grand child modules.

Parameters
$id : string

module ID (case-sensitive). To retrieve grand child modules, use ID path relative to this module (e.g. admin/content).

$load : bool = true

whether to load the module if it is not yet loaded.

Tags
see
hasModule()
Return values
Module|null

the module instance, null if the module does not exist.

getModuleInstance()

public static getModuleInstance() : static
Return values
static

getModules()

Returns the sub-modules in this module.

public getModules([bool $loadedOnly = false ]) : array<string|int, mixed>
Parameters
$loadedOnly : bool = false

whether to return the loaded sub-modules only. If this is set false, then all sub-modules registered in this module will be returned, whether they are loaded or not. Loaded modules will be returned as objects, while unloaded modules as configuration arrays.

Return values
array<string|int, mixed>

the modules (indexed by their IDs).

getName()

Returns the module's name provided by module.json file

public getName() : string
Return values
string

Name

getNotifications()

Returns a list of notification classes this module provides.

public getNotifications() : array<string|int, mixed>
Tags
since
1.1
Return values
array<string|int, mixed>

list of notification classes

getPermissions()

Returns a list of permission objects this module provides.

public getPermissions([ContentContainerActiveRecord $contentContainer = null ]) : array<string|int, mixed>

If a content container is provided, the method should only return applicable permissions for the given container. This function should also make sure the module is installed on the given container in case the permission only affects installed features.

Parameters
$contentContainer : ContentContainerActiveRecord = null

optional contentcontainer

Tags
since
0.21
Return values
array<string|int, mixed>

list of permissions

getPublishedUrl()

Returns the url of an asset file and publishes all module assets if the file is not published yet.

public getPublishedUrl(string $relativePath) : string
Parameters
$relativePath : string

relative file path e.g. /module_image.jpg

Return values
string

getUniqueId()

Returns an ID that uniquely identifies this module among all modules within the current application.

public getUniqueId() : string

Note that if the module is an application, an empty string will be returned.

Return values
string

the unique ID of the module.

getVersion()

Returns the module's version number provided by module.json file

public getVersion() : string
Return values
string

Version Number

getViewPath()

Returns the directory that contains the view files for this module.

public getViewPath() : string
Return values
string

the root directory of view files. Defaults to "[[basePath]]/views".

has()

Returns a value indicating whether the locator has the specified component definition or has instantiated the component.

public has(mixed $id[, mixed $checkInstance = false ]) : bool

Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. The parent module may be the application.

Parameters
$id : mixed

component ID (e.g. db).

$checkInstance : mixed = false

whether the method should check if the component is shared and instantiated.

Return values
bool

whether the locator has the specified component definition or has instantiated the component.

hasEventHandlers()

Returns a value indicating whether there is any handler attached to the named event.

public hasEventHandlers(string $name) : bool
Parameters
$name : string

the event name

Return values
bool

whether there is any handler attached to the event.

hasMethod()

Returns a value indicating whether a method is defined.

public hasMethod(string $name[, bool $checkBehaviors = true ]) : bool

A method is defined if:

  • the class has a method with the specified name
  • an attached behavior has a method with the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkBehaviors : bool = true

whether to treat behaviors' methods as methods of this component

Return values
bool

whether the method is defined

hasModule()

Checks whether the child module of the specified ID exists.

public hasModule(string $id) : bool

This method supports checking the existence of both child and grand child modules.

Parameters
$id : string

module ID. For grand child modules, use ID path relative to this module (e.g. admin/content).

Return values
bool

whether the named module exists. Both loaded and unloaded modules are considered.

hasNotifications()

Determines whether the module has notification classes or not

public hasNotifications() : bool
Tags
since
1.2
Return values
bool

has notifications

hasProperty()

Returns a value indicating whether a property is defined for this component.

public hasProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canGetProperty()
see
canSetProperty()
Return values
bool

whether the property is defined

init()

Initializes the module.

public init() : mixed
Tags
inheritdoc

isPublished()

Checks if a specific asset file has already been published

public isPublished(string $relativePath) : string
Parameters
$relativePath : string
Return values
string

migrate()

Execute all not applied module migrations

public migrate() : mixed
Tags
deprecated

since v1.16; use static::getMigrationService()->migrateUp()

off()

Detaches an existing event handler from this component.

public off(string $name[, callable|null $handler = null ]) : bool

This method is the opposite of [[on()]].

Note: in case wildcard pattern is passed for event name, only the handlers registered with this wildcard will be removed, while handlers registered with plain names matching this wildcard will remain.

Parameters
$name : string

event name

$handler : callable|null = null

the event handler to be removed. If it is null, all handlers attached to the named event will be removed.

Tags
see
on()
Return values
bool

if a handler is found and detached

on()

Attaches an event handler to an event.

public on(string $name, callable $handler[, mixed $data = null ][, bool $append = true ]) : mixed

The event handler must be a valid PHP callback. The following are some examples:

function ($event) { ... }         // anonymous function
[$object, 'handleClick']          // $object->handleClick()
['Page', 'handleClick']           // Page::handleClick()
'handleClick'                     // global function handleClick()

The event handler must be defined with the following signature,

function ($event)

where $event is an [[Event]] object which includes parameters associated with the event.

Since 2.0.14 you can specify event name as a wildcard pattern:

$component->on('event.group.*', function ($event) {
    Yii::trace($event->name . ' is triggered.');
});
Parameters
$name : string

the event name

$handler : callable

the event handler

$data : mixed = null

the data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via [[Event::data]].

$append : bool = true

whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list.

Tags
see
off()

publishAssets()

Publishes the basePath/resourcesPath (assets) module directory if existing.

public publishAssets([bool $all = false ]) : array<string|int, mixed>
Parameters
$all : bool = false

whether or not to publish sub assets within the assets directory

Return values
array<string|int, mixed>

runAction()

Runs a controller action specified by a route.

public runAction(string $route[, array<string|int, mixed> $params = [] ]) : mixed

This method parses the specified route and creates the corresponding child module(s), controller and action instances. It then calls [[Controller::runAction()]] to run the action with the given parameters. If the route is empty, the method will use [[defaultRoute]].

Parameters
$route : string

the route that specifies the action.

$params : array<string|int, mixed> = []

the parameters to be passed to the action

Tags
throws
InvalidRouteException

if the requested route cannot be resolved into an action successfully.

Return values
mixed

the result of the action.

set()

Registers a component definition with this locator.

public set(string $id, mixed $definition) : mixed

For example,

// a class name
$locator->set('cache', 'yii\caching\FileCache');

// a configuration array
$locator->set('db', [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
]);

// an anonymous function
$locator->set('cache', function ($params) {
    return new \yii\caching\FileCache;
});

// an instance
$locator->set('cache', new \yii\caching\FileCache);

If a component definition with the same ID already exists, it will be overwritten.

Parameters
$id : string

component ID (e.g. db).

$definition : mixed

the component definition to be registered with this locator. It can be one of the following:

  • a class name
  • a configuration array: the array contains name-value pairs that will be used to initialize the property values of the newly created object when [[get()]] is called. The class element is required and stands for the the class of the object to be created.
  • a PHP callable: either an anonymous function or an array representing a class method (e.g. ['Foo', 'bar']). The callable will be called by [[get()]] to return an object associated with the specified component ID.
  • an object: When [[get()]] is called, this object will be returned.
Tags
throws
InvalidConfigException

if the definition is an invalid configuration array

setAliases()

Defines path aliases.

public setAliases(array<string|int, mixed> $aliases) : mixed

This method calls [[Yii::setAlias()]] to register the path aliases. This method is provided so that you can define path aliases when configuring a module.

Parameters
$aliases : array<string|int, mixed>

list of path aliases to be defined. The array keys are alias names (must start with @) and the array values are the corresponding paths or aliases. For example,

[
    '@models' => '@app/models', // an existing alias
    '@backend' => __DIR__ . '/../backend',  // a directory
]
Tags
@property

array list of path aliases to be defined. The array keys are alias names (must start with @) and the array values are the corresponding paths or aliases. See [[setAliases()]] for an example.

setBasePath()

Sets the root directory of the module.

public setBasePath(string $path) : mixed

This method can only be invoked at the beginning of the constructor.

Parameters
$path : string

the root directory of the module. This can be either a directory name or a path alias.

Tags
throws
InvalidArgumentException

if the directory does not exist.

setComponents()

Registers a set of component definitions in this locator.

public setComponents(array<string|int, mixed> $components) : mixed

This is the bulk version of [[set()]]. The parameter should be an array whose keys are component IDs and values the corresponding component definitions.

For more details on how to specify component IDs and definitions, please refer to [[set()]].

If a component definition with the same ID already exists, it will be overwritten.

The following is an example for registering two component definitions:

[
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'sqlite:path/to/file.db',
    ],
    'cache' => [
        'class' => 'yii\caching\DbCache',
        'db' => 'db',
    ],
]
Parameters
$components : array<string|int, mixed>

component definitions or instances

setControllerPath()

Sets the directory that contains the controller classes.

public setControllerPath(string $path) : mixed
Parameters
$path : string

the root directory that contains the controller classes.

Tags
throws
InvalidArgumentException

if the directory is invalid.

since
2.0.44

setInstance()

Sets the currently requested instance of this module class.

public static setInstance(Module|null $instance) : mixed
Parameters
$instance : Module|null

the currently requested instance of this module class. If it is null, the instance of the calling class will be removed, if any.

setLayoutPath()

Sets the directory that contains the layout files.

public setLayoutPath(string $path) : mixed
Parameters
$path : string

the root directory or path alias of layout files.

Tags
throws
InvalidArgumentException

if the directory is invalid

setModule()

Adds a sub-module to this module.

public setModule(string $id, Module|array<string|int, mixed>|null $module) : mixed
Parameters
$id : string

module ID.

$module : Module|array<string|int, mixed>|null

the sub-module to be added to this module. This can be one of the following:

  • a [[Module]] object
  • a configuration array: when [[getModule()]] is called initially, the array will be used to instantiate the sub-module
  • null: the named sub-module will be removed from this module

setModules()

Registers sub-modules in the current module.

public setModules(array<string|int, mixed> $modules) : mixed

Each sub-module should be specified as a name-value pair, where name refers to the ID of the module and value the module or a configuration array that can be used to create the module. In the latter case, [[Yii::createObject()]] will be used to create the module.

If a new sub-module has the same ID as an existing one, the existing one will be overwritten silently.

The following is an example for registering two sub-modules:

[
    'comment' => [
        'class' => 'app\modules\comment\CommentModule',
        'db' => 'db',
    ],
    'booking' => ['class' => 'app\modules\booking\BookingModule'],
]
Parameters
$modules : array<string|int, mixed>

modules (id => module configuration or instances).

setVersion()

Sets current module version.

public setVersion(string|callable|null $version) : mixed
Parameters
$version : string|callable|null

the version of this module. Version can be specified as a PHP callback, which can accept module instance as an argument and should return the actual version. For example:

function (Module $module) {
    //return string
}
Tags
since
2.0.11

setViewPath()

Sets the directory that contains the view files.

public setViewPath(string $path) : mixed
Parameters
$path : string

the root directory of view files.

Tags
throws
InvalidArgumentException

if the directory is invalid.

trigger()

Triggers an event.

public trigger(string $name[, Event|null $event = null ]) : mixed

This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.

Parameters
$name : string

the event name

$event : Event|null = null

the event instance. If not set, a default [[Event]] object will be created.

update()

This method is called after an update is performed.

public update() : mixed

You may extend it with your own update process.

defaultVersion()

Returns default module version.

protected defaultVersion() : string

Child class may override this method to provide more specific version detection.

Tags
since
2.0.11
Return values
string

the version of this module.

getModuleInfo()

Reads module.json which contains basic module information and returns it as array

protected getModuleInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

module.json content

attachBehaviorInternal()

Attaches a behavior to this component.

private attachBehaviorInternal(string|int $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior
Parameters
$name : string|int

the name of the behavior. If this is an integer, it means the behavior is an anonymous one. Otherwise, the behavior is a named one and any existing behavior with the same name will be detached first.

$behavior : string|array<string|int, mixed>|Behavior

the behavior to be attached

Return values
Behavior

the attached behavior.

hasAssets()

Determines whether or not this module has an asset directory.

private hasAssets() : bool
Return values
bool

isIncorrectClassNameOrPrefix()

Checks if class name or prefix is incorrect

private isIncorrectClassNameOrPrefix(string $className, string $prefix) : bool
Parameters
$className : string
$prefix : string
Return values
bool

        
On this page

Search results