system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CModule

system.base
继承 abstract class CModule » CComponent
子类 CApplication, CWebModule
可用自 1.0.4
版本 $Id$
CModule is the base class for module and application classes.

CModule mainly manages application components and sub-modules.

公共属性

隐藏继承的属性

属性类型描述被定义在
basePath string the root directory of the module. CModule
behaviors array the behaviors that should be attached to the module. CModule
components array the currently loaded components (indexed by their IDs) CModule
id string the module ID. CModule
modulePath string the directory that contains the application modules. CModule
modules array the configuration of the currently installed modules (module ID => configuration) CModule
params CAttributeCollection the list of user-defined parameters CModule
parentModule CModule the parent module. CModule
preload array the IDs of the application components that should be preloaded. CModule

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CModule
__get() Getter magic method. CModule
__isset() Checks if a property value is null. CModule
__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. CModule
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() CModule
getComponent() Retrieves the named application component. CModule
getComponents() CModule
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() CModule
getModule() Retrieves the named application module. CModule
getModulePath() CModule
getModules() CModule
getParams() CModule
getParentModule() CModule
hasComponent() CModule
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
raiseEvent() Raises an event. CComponent
setAliases() Defines the root aliases. CModule
setBasePath() Sets the root directory of the module. CModule
setComponent() Puts a component under the management of the module. CModule
setComponents() Sets the application components. CModule
setId() CModule
setImport() Sets the aliases that are used in the module. CModule
setModulePath() CModule
setModules() Configures the sub-modules of this module. CModule
setParams() CModule

受保护的方法

隐藏继承的方法

方法描述被定义在
init() Initializes the module. CModule
preinit() Preinitializes the module. CModule
preloadComponents() Loads static application components. CModule

属性详情

basePath 属性
public string getBasePath()
public void setBasePath(string $path)

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

behaviors 属性
public array $behaviors;

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

components 属性
public array getComponents()
public void setComponents(array $components)

the currently loaded components (indexed by their IDs)

id 属性
public string getId()
public void setId(string $id)

the module ID.

modulePath 属性
public string getModulePath()
public void setModulePath(string $value)

the directory that contains the application modules. Defaults to the 'modules' subdirectory of basePath.

modules 属性
public array getModules()
public void setModules(array $modules)

the configuration of the currently installed modules (module ID => configuration)

params 属性
public CAttributeCollection getParams()
public void setParams(array $value)

the list of user-defined parameters

parentModule 属性 只读
public CModule getParentModule()

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

preload 属性
public array $preload;

the IDs of the application components that should be preloaded.

方法详情

__construct() 方法
public void __construct(string $id, CModule $parent, mixed $config=NULL)
$id string the ID of this module
$parent CModule the parent module (if any)
$config mixed the module configuration. It can be either an array or the path of a PHP file returning the configuration array.

Constructor.

__get() 方法
public mixed __get(string $name)
$name string application component or property name
{return} mixed the named property value

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

__isset() 方法
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 application component is loaded.

configure() 方法
public void configure(array $config)
$config array the configuration array

Configures the module with the specified configuration.

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

getComponent() 方法
public IApplicationComponent getComponent(string $id, boolean $createIfNull=true)
$id string application component ID (case-sensitive)
$createIfNull boolean whether to create the component if it doesn't exist yet. This parameter has been available since version 1.0.6.
{return} IApplicationComponent the application component instance, null if the application component is disabled or does not exist.

Retrieves the named application component.

参见

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

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

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

Retrieves the named application module. The module has to be declared in modules. A new instance will be created when calling this method with the given ID for the first time.

getModulePath() 方法
public string getModulePath()
{return} string the directory that contains the application modules. Defaults to the 'modules' subdirectory of basePath.

getModules() 方法
public array getModules()
{return} array the configuration of the currently installed modules (module ID => configuration)

getParams() 方法
public CAttributeCollection getParams()
{return} CAttributeCollection the list of user-defined parameters

getParentModule() 方法
public CModule getParentModule()
{return} CModule the parent module. Null if this module does not have a parent.

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

init() 方法
protected void init()

Initializes the module. This method is called at the end of the module constructor. Note that at this moment, the module has been configured, the behaviors have been attached and the application components have been registered.

参见

preinit() 方法
protected void preinit()

Preinitializes the module. This method is called at the beginning of the module constructor. You may override this method to do some customized preinitialization work. Note that at this moment, the module is not configured yet.

参见

preloadComponents() 方法
protected void preloadComponents()

Loads static application components.

setAliases() 方法 (自版本 v1.0.5 可用)
public void setAliases(array $mappings)
$mappings array list of aliases to be defined. The array keys are root aliases, while the array values are paths or aliases corresponding to the root aliases. For example,
array(
   'models'=>'application.models',              // an existing alias
   'extensions'=>'application.extensions',      // an existing alias
   'backend'=>dirname(__FILE__).'/../backend',  // a directory
)

Defines the root aliases.

setBasePath() 方法
public void setBasePath(string $path)
$path string the root directory of the module.

Sets the root directory of the module. This method can only be invoked at the beginning of the constructor.

setComponent() 方法
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() 方法
public void setComponents(array $components)
$components array application components(id=>component configuration or instances)

Sets the application 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
    ),
)

setId() 方法
public void setId(string $id)
$id string the module ID

setImport() 方法
public void setImport(array $aliases)
$aliases array list of aliases to be imported

Sets the aliases that are used in the module.

setModulePath() 方法
public void setModulePath(string $value)
$value string the directory that contains the application modules.

setModules() 方法
public void setModules(array $modules)
$modules array module configurations.

Configures the sub-modules of 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-configuration pair representing a module with the specified ID and the initial property values.

For example, the following array declares two modules:

array(
    'admin',                // a single module ID
    'payment'=>array(       // ID-configuration pair
        '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() 方法
public void setParams(array $value)
$value array user-defined parameters. This should be in name-value pairs.