CWebModule

Package system.web
Inheritance class CWebModule » CComponent
Since 1.0.3
Version $Id: CWebModule.php 738 2009-02-24 16:53:24Z qiang.xue $
CWebModule represents an application module.

An application module may be considered as a self-contained sub-application that has its own controllers, models and views and can be reused in a different project as a whole. Controllers inside a module must be accessed with routes that are prefixed with the module ID.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
basePath string the root directory of the module. CWebModule
behaviors array the behaviors that should be attached to the module. CWebModule
components array the currently loaded components (indexed by their IDs) CWebModule
controllerMap array mapping from controller ID to controller configurations. CWebModule
controllerPath string the directory that contains the controller classes. CWebModule
defaultController string the ID of the default controller for this module. CWebModule
description string Returns the description of this module. CWebModule
id string the module ID. CWebModule
layout mixed the layout that is shared by the controllers inside this module. CWebModule
layoutPath string the root directory of layout files. CWebModule
modulePath string the directory that contains the modules. CWebModule
modules array the currently loaded application modules (indexed by their IDs) CWebModule
name string Returns the name of this module. CWebModule
params CAttributeCollection the list of module parameters CWebModule
parentModule CWebModule the parent module. CWebModule
preload array the IDs of the module components that should be preloaded. CWebModule
version string Returns the version of this module. CWebModule
viewPath string the root directory of view files. CWebModule

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CWebModule
__get() Getter magic method. CWebModule
__isset() Checks if a property value is null. CWebModule
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
configure() Configures the module with the specified configuration. CWebModule
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
getBasePath() CWebModule
getComponent() Retrieves the named module component. CWebModule
getComponents() CWebModule
getControllerPath() CWebModule
getDescription() Returns the description of this module. CWebModule
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() CWebModule
getLayoutPath() CWebModule
getModule() Retrieves the named application module. CWebModule
getModulePath() CWebModule
getModules() CWebModule
getName() Returns the name of this module. CWebModule
getParams() CWebModule
getParentModule() CWebModule
getVersion() Returns the version of this module. CWebModule
getViewPath() CWebModule
hasComponent() CWebModule
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
init() Initializes this module. CWebModule
raiseEvent() Raises an event. CComponent
setComponent() Puts a component under the management of the module. CWebModule
setComponents() Sets the module components. CWebModule
setModules() Configures the modules belonging to this module. CWebModule
setParams() CWebModule

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
preloadComponents() Loads static module components. CWebModule

Property Details

basePath property read-only
public string getBasePath()

the root directory of the module. Defaults to the directory containing the module class.

behaviors property
public array $behaviors;

the behaviors that should be attached to the module. The behaviors will be attached to the application when init is called. Please refer to CModel::behaviors on how to specify the value of this property.

components property
public array getComponents()
public void setComponents(array $components)

the currently loaded components (indexed by their IDs)

controllerMap property
public array $controllerMap;

mapping from controller ID to controller configurations. Pleaser refer to CWebApplication::controllerMap for more details.

controllerPath property read-only
public string getControllerPath()

the directory that contains the controller classes. Defaults to the "controllers" sub-directory of basePath.

defaultController property
public string $defaultController;

the ID of the default controller for this module. Defaults to 'default'.

description property read-only
public string getDescription()

Returns the description of this module. The default implementation returns an empty string. You may override this method to customize the description of this module.

id property read-only
public string getId()

the module ID.

layout property
public mixed $layout;

the layout that is shared by the controllers inside this module. If a controller has explicitly declared its own layout, this property will be ignored. If this is null (default), the application's layout or the parent module's layout (if available) will be used. If this is false, then no layout will be used.

layoutPath property read-only
public string getLayoutPath()

the root directory of layout files. Defaults to the "layouts" sub-directory of viewPath.

modulePath property read-only
public string getModulePath()

the directory that contains the modules. Defaults to the "modules" sub-directory of basePath.

modules property
public array getModules()
public void setModules(array $modules)

the currently loaded application modules (indexed by their IDs)

name property read-only
public string getName()

Returns the name of this module. The default implementation simply returns id. You may override this method to customize the name of this module.

params property
public CAttributeCollection getParams()
public void setParams(array $value)

the list of module parameters

parentModule property read-only
public CWebModule getParentModule()

the parent module. Null if this module does not have parent.

preload property
public array $preload;

the IDs of the module components that should be preloaded.

version property read-only
public string getVersion()

Returns the version of this module. The default implementation returns '1.0'. You may override this method to customize the version of this module.

viewPath property read-only
public string getViewPath()

the root directory of view files. Defaults to the "views" sub-directory of basePath.

Method Details

__construct() method
public void __construct(string $id, CWebModule $parent=NULL)
$id string the ID of this module
$parent CWebModule the parent module (if any)

Constructor.

__get() method
public mixed __get(string $name)
$name string module component or property name
{return} mixed the named property value

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

__isset() method (available since v1.0.1)
public boolean __isset(string $name)
$name string the property name or the event name
{return} boolean whether the property value is null

Checks if a property value is null. This method overrides the parent implementation by checking if the named module component is loaded.

configure() method
public void configure(mixed $config)
$config mixed the configuration array or a PHP script returning the configuration array.

Configures the module with the specified configuration.

getBasePath() method
public string getBasePath()
{return} string the root directory of the module. Defaults to the directory containing the module class.

getComponent() method
public IApplicationComponent getComponent(string $id)
$id string application component ID (case-sensitive)
{return} IApplicationComponent the module component instance, null if the module component is disabled or does not exist.

Retrieves the named module component.

See Also

getComponents() method
public array getComponents()
{return} array the currently loaded components (indexed by their IDs)

getControllerPath() method
public string getControllerPath()
{return} string the directory that contains the controller classes. Defaults to the "controllers" sub-directory of basePath.

getDescription() method
public string getDescription()
{return} string the description of this module.

Returns the description of this module. The default implementation returns an empty string. You may override this method to customize the description of this module.

getId() method
public string getId()
{return} string the module ID.

getLayoutPath() method
public string getLayoutPath()
{return} string the root directory of layout files. Defaults to the "layouts" sub-directory of viewPath.

getModule() method
public CWebModule getModule(string $id)
$id string application module ID (case-sensitive)
{return} CWebModule the application module instance, null if the application module is disabled or does not exist.

Retrieves the named application module.

getModulePath() method
public string getModulePath()
{return} string the directory that contains the modules. Defaults to the "modules" sub-directory of basePath.

getModules() method
public array getModules()
{return} array the currently loaded application modules (indexed by their IDs)

getName() method
public string getName()
{return} string the name of this module.

Returns the name of this module. The default implementation simply returns id. You may override this method to customize the name of this module.

getParams() method
public CAttributeCollection getParams()
{return} CAttributeCollection the list of module parameters

getParentModule() method
public CWebModule getParentModule()
{return} CWebModule the parent module. Null if this module does not have parent.

getVersion() method
public string getVersion()
{return} string the version of this module.

Returns the version of this module. The default implementation returns '1.0'. You may override this method to customize the version of this module.

getViewPath() method
public string getViewPath()
{return} string the root directory of view files. Defaults to the "views" sub-directory of basePath.

hasComponent() method
public boolean hasComponent(string $id)
$id string module component ID
{return} boolean whether the named module component exists (including both loaded and disabled.)

init() method
public void init(mixed $config)
$config mixed the configuration array or a PHP script returning the configuration array. The configuration will be applied to this module.

Initializes this module. This method is invoked automatically when the module is initially created. You may override this method to customize the module or the application. Make sure you call the parent implementation so that the module gets configured.

preloadComponents() method
protected void preloadComponents()

Loads static module components.

setComponent() method
public void setComponent(string $id, IApplicationComponent $component)
$id string component ID
$component IApplicationComponent the component

Puts a component under the management of the module. The component will be initialized (by calling its init() method if it has not done so.

setComponents() method
public void setComponents(array $components)
$components array module components(id=>component configuration or instances)

Sets the module components.

When a configuration is used to specify a component, it should consist of the component's initial property values (name-value pairs). Additionally, a component can be enabled (default) or disabled by specifying the 'enabled' value in the configuration.

If a configuration is specified with an ID that is the same as an existing component or configuration, the existing one will be replaced silently.

The following is the configuration for two components:

array(
    'db'=>array(
        'class'=>'CDbConnection',
        'connectionString'=>'sqlite:path/to/file.db',
    ),
    'cache'=>array(
        'class'=>'CDbCache',
        'connectionID'=>'db',
        'enabled'=>!YII_DEBUG,  // enable caching in non-debug mode
    ),
)

setModules() method
public void setModules(array $modules)
$modules array application module configuration.

Configures the modules belonging to this module.

Call this method to declare sub-modules and configure them with their initial property values. The parameter should be an array of module configurations. Each array element represents a single module, which can be either a string representing the module ID or an ID-config pair representing a module with the specified ID and the initial property values.

For example, the following array declares two modules:

array(
    'admin',
    'payment'=>array(
        'server'=>'paymentserver.com',
    ),
)


By default, the module class is determined using the expression ucfirst($moduleID).'Module'. And the class file is located under modules/$moduleID. You may override this default by explicitly specifying the 'class' option in the configuration.

You may also enable or disable a module by specifying the 'enabled' option in the configuration.

setParams() method
public void setParams(array $value)
$value array module parameters. This should be in name-value pairs.