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 $ |
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
| Property | Type | Description | Defined 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
| Method | Description | Defined 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
| Method | Description | Defined By |
|---|---|---|
| preloadComponents() | Loads static module components. | CWebModule |
Property Details
the root directory of the module. Defaults to the directory containing the module class.
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.
the currently loaded components (indexed by their IDs)
mapping from controller ID to controller configurations. Pleaser refer to CWebApplication::controllerMap for more details.
the directory that contains the controller classes. Defaults to the "controllers" sub-directory of basePath.
the ID of the default controller for this module. Defaults to 'default'.
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.
the module ID.
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.
the root directory of layout files. Defaults to the "layouts" sub-directory of viewPath.
the directory that contains the modules. Defaults to the "modules" sub-directory of basePath.
the currently loaded application modules (indexed by their IDs)
Returns the name of this module. The default implementation simply returns id. You may override this method to customize the name of this module.
the list of module parameters
the parent module. Null if this module does not have parent.
the IDs of the module components that should be preloaded.
Returns the version of this module. The default implementation returns '1.0'. You may override this method to customize the version of this module.
the root directory of view files. Defaults to the "views" sub-directory of basePath.
Method Details
|
public void __construct(string $id, CWebModule $parent=NULL)
| ||
| $id | string | the ID of this module |
| $parent | CWebModule | the parent module (if any) |
Constructor.
|
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.
|
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.
|
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.
|
public string getBasePath()
| ||
| {return} | string | the root directory of the module. Defaults to the directory containing the module class. |
|
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
|
public array getComponents()
| ||
| {return} | array | the currently loaded components (indexed by their IDs) |
|
public string getControllerPath()
| ||
| {return} | string | the directory that contains the controller classes. Defaults to the "controllers" sub-directory of basePath. |
|
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.
|
public string getId()
| ||
| {return} | string | the module ID. |
|
public string getLayoutPath()
| ||
| {return} | string | the root directory of layout files. Defaults to the "layouts" sub-directory of viewPath. |
|
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.
|
public string getModulePath()
| ||
| {return} | string | the directory that contains the modules. Defaults to the "modules" sub-directory of basePath. |
|
public array getModules()
| ||
| {return} | array | the currently loaded application modules (indexed by their IDs) |
|
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.
|
public CAttributeCollection getParams()
| ||
| {return} | CAttributeCollection | the list of module parameters |
|
public CWebModule getParentModule()
| ||
| {return} | CWebModule | the parent module. Null if this module does not have parent. |
|
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.
|
public string getViewPath()
| ||
| {return} | string | the root directory of view files. Defaults to the "views" sub-directory of basePath. |
|
public boolean hasComponent(string $id)
| ||
| $id | string | module component ID |
| {return} | boolean | whether the named module component exists (including both loaded and disabled.) |
|
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.
|
protected void preloadComponents()
|
Loads static module components.
|
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.
|
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
),
)
|
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.
|
public void setParams(array $value)
| ||
| $value | array | module parameters. This should be in name-value pairs. |