0 follower

CWebModule

Package system.web
Inheritance class CWebModule » CModule » CComponent
Since 1.0.3
Version $Id$
Source Code framework/web/CWebModule.php
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. CModule
behaviors array the behaviors that should be attached to the module. CModule
components array the currently loaded components (indexed by their IDs) CModule
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. CModule
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 application modules. CModule
modules array the configuration of the currently installed modules (module ID => configuration) CModule
name string Returns the name of this module. CWebModule
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
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. 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
afterControllerAction() The post-filter for controller actions. CWebModule
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
beforeControllerAction() The pre-filter for controller actions. CWebModule
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() Returns the root directory of the module. Defaults to the directory containing the module class. CModule
getComponent() Retrieves the named application component. CModule
getComponents() Returns the currently loaded components (indexed by their IDs) CModule
getControllerPath() Returns the directory that contains the controller classes. Defaults to 'protected/controllers'. CWebModule
getDescription() Returns the description of this module. CWebModule
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() Returns the module ID. CModule
getLayoutPath() Returns the root directory of layout files. Defaults to 'protected/views/layouts'. CWebModule
getModule() Retrieves the named application module. CModule
getModulePath() Returns the directory that contains the application modules. Defaults to the 'modules' subdirectory of basePath. CModule
getModules() Returns the configuration of the currently installed modules (module ID => configuration) CModule
getName() Returns the name of this module. CWebModule
getParams() Returns the list of user-defined parameters CModule
getParentModule() Returns the parent module. Null if this module does not have a parent. CModule
getVersion() Returns the version of this module. CWebModule
getViewPath() Returns the root directory of view files. Defaults to 'protected/views'. CWebModule
hasComponent() Determines whether the named application component exists (including both loaded and disabled.) 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
setControllerPath() Sets the directory that contains the controller classes. CWebModule
setId() Sets the module ID CModule
setImport() Sets the aliases that are used in the module. CModule
setLayoutPath() Sets the root directory of layout files. CWebModule
setModulePath() Sets the directory that contains the application modules. CModule
setModules() Configures the sub-modules of this module. CModule
setParams() Sets user-defined parameters. This should be in name-value pairs. CModule
setViewPath() Sets the root directory of view files. CWebModule

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
init() Initializes the module. CModule
preinit() Preinitializes the module. CModule
preloadComponents() Loads static application components. CModule

Property Details

controllerMap property
public array $controllerMap;

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

controllerPath property
public string getControllerPath()
public void setControllerPath(string $value)

the directory that contains the controller classes. Defaults to 'protected/controllers'.

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.

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
public string getLayoutPath()
public void setLayoutPath(string $path)

the root directory of layout files. Defaults to 'protected/views/layouts'.

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.

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
public string getViewPath()
public void setViewPath(string $path)

the root directory of view files. Defaults to 'protected/views'.

Method Details

afterControllerAction() method (available since v1.0.4)
public void afterControllerAction(CController $controller, CAction $action)
$controller CController the controller
$action CAction the action
Source Code: framework/web/CWebModule.php#181 (show)
public function afterControllerAction($controller,$action)
{
    if((
$parent=$this->getParentModule())===null)
        
$parent=Yii::app();
    
$parent->afterControllerAction($controller,$action);
}

The post-filter for controller actions. This method is invoked after the currently requested controller action and all its filters are executed. If you override this method, make sure you call the parent implementation at the end.

beforeControllerAction() method (available since v1.0.4)
public boolean beforeControllerAction(CController $controller, CAction $action)
$controller CController the controller
$action CAction the action
{return} boolean whether the action should be executed.
Source Code: framework/web/CWebModule.php#166 (show)
public function beforeControllerAction($controller,$action)
{
    if((
$parent=$this->getParentModule())===null)
        
$parent=Yii::app();
    return 
$parent->beforeControllerAction($controller,$action);
}

The pre-filter for controller actions. This method is invoked before the currently requested controller action and all its filters are executed. You may override this method in the following way:

if(parent::beforeControllerAction($controller,$action))
{
    // your code
    return true;
}
else
    return false;

getControllerPath() method
public string getControllerPath()
{return} string the directory that contains the controller classes. Defaults to 'protected/controllers'.
Source Code: framework/web/CWebModule.php#85 (show)
public function getControllerPath()
{
    if(
$this->_controllerPath!==null)
        return 
$this->_controllerPath;
    else
        return 
$this->_controllerPath=$this->getBasePath().DIRECTORY_SEPARATOR.'controllers';
}

getDescription() method
public string getDescription()
{return} string the description of this module.
Source Code: framework/web/CWebModule.php#66 (show)
public function getDescription()
{
    return 
'';
}

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.

getLayoutPath() method
public string getLayoutPath()
{return} string the root directory of layout files. Defaults to 'protected/views/layouts'.
Source Code: framework/web/CWebModule.php#129 (show)
public function getLayoutPath()
{
    if(
$this->_layoutPath!==null)
        return 
$this->_layoutPath;
    else
        return 
$this->_layoutPath=$this->getViewPath().DIRECTORY_SEPARATOR.'layouts';
}

getName() method
public string getName()
{return} string the name of this module.
Source Code: framework/web/CWebModule.php#55 (show)
public function getName()
{
    return 
basename($this->getId());
}

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

getVersion() method
public string getVersion()
{return} string the version of this module.
Source Code: framework/web/CWebModule.php#77 (show)
public function getVersion()
{
    return 
'1.0';
}

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 'protected/views'.
Source Code: framework/web/CWebModule.php#107 (show)
public function getViewPath()
{
    if(
$this->_viewPath!==null)
        return 
$this->_viewPath;
    else
        return 
$this->_viewPath=$this->getBasePath().DIRECTORY_SEPARATOR.'views';
}

setControllerPath() method
public void setControllerPath(string $value)
$value string the directory that contains the controller classes.
Source Code: framework/web/CWebModule.php#97 (show)
public function setControllerPath($value)
{
    if((
$this->_controllerPath=realpath($value))===false || !is_dir($this->_controllerPath))
        throw new 
CException(Yii::t('yii','The controller path "{path}" is not a valid directory.',
            array(
'{path}'=>$value)));
}

setLayoutPath() method
public void setLayoutPath(string $path)
$path string the root directory of layout files.
Source Code: framework/web/CWebModule.php#141 (show)
public function setLayoutPath($path)
{
    if((
$this->_layoutPath=realpath($path))===false || !is_dir($this->_layoutPath))
        throw new 
CException(Yii::t('yii','The layout path "{path}" is not a valid directory.',
            array(
'{path}'=>$path)));
}

setViewPath() method
public void setViewPath(string $path)
$path string the root directory of view files.
Source Code: framework/web/CWebModule.php#119 (show)
public function setViewPath($path)
{
    if((
$this->_viewPath=realpath($path))===false || !is_dir($this->_viewPath))
        throw new 
CException(Yii::t('yii','The view path "{path}" is not a valid directory.',
            array(
'{path}'=>$path)));
}