system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CWebApplication

system.web
继承 class CWebApplication » CApplication » CModule » CComponent
可用自 1.0
源码 framework/web/CWebApplication.php
CWebApplication extends CApplication by providing functionalities specific to Web requests.

CWebApplication manages the controllers in MVC pattern, and provides the following additional core application components:
  • urlManager: provides URL parsing and constructing functionality;
  • request: encapsulates the Web request information;
  • session: provides the session-related functionalities;
  • assetManager: manages the publishing of private asset files.
  • user: represents the user session information.
  • themeManager: manages themes.
  • authManager: manages role-based access control (RBAC).
  • clientScript: manages client scripts (javascripts and CSS).
  • widgetFactory: creates widgets and supports widget skinning.


User requests are resolved as controller-action pairs and additional parameters. CWebApplication creates the requested controller instance and let it to handle the actual user request. If the user does not specify controller ID, it will assume defaultController is requested (which defaults to 'site').

Controller class files must reside under the directory controllerPath (defaults to 'protected/controllers'). The file name and the class name must be the same as the controller ID with the first letter in upper case and appended with 'Controller'. For example, the controller 'article' is defined by the class 'ArticleController' which is in the file 'protected/controllers/ArticleController.php'.

公共属性

隐藏继承的属性

属性类型描述被定义在
assetManager CAssetManager the asset manager component CWebApplication
authManager IAuthManager the authorization manager component CWebApplication
basePath string Returns the root path of the application. CApplication
baseUrl string Returns the relative URL for the application. CApplication
behaviors array the behaviors that should be attached to the module. CModule
cache CCache Returns the cache component. CApplication
catchAllRequest array the configuration specifying a controller which should handle all user requests. CWebApplication
charset string the charset currently used for the application. CApplication
clientScript CClientScript Returns the client script manager. CWebApplication
components array 返回应用程序组件。 CModule
controller CController the currently active controller CWebApplication
controllerMap array mapping from controller ID to controller configurations. CWebApplication
controllerNamespace string Namespace that should be used when loading controllers. CWebApplication
controllerPath string the directory that contains the controller classes. CWebApplication
coreMessages CPhpMessageSource Returns the core message translations component. CApplication
dateFormatter CDateFormatter Returns the locale-dependent date formatter. CApplication
db CDbConnection Returns the database connection component. CApplication
defaultController string the route of the default controller, action or module. CWebApplication
errorHandler CErrorHandler Returns the error handler component. CApplication
extensionPath string Returns the root directory that holds all third-party extensions. CApplication
format CFormatter Returns the formatter component. CApplication
homeUrl string the homepage URL CApplication
id string 返回应用程序唯一的标识。 CApplication
language string Returns the language that the user is using and the application should be targeted to. CApplication
layout mixed the application-wide layout. CWebApplication
layoutPath string the root directory of layout files. CWebApplication
locale CLocale Returns the locale instance. CApplication
localeClass string the class used to get locale data. CApplication
localeDataPath string Returns the directory that contains the locale data. CApplication
messages CMessageSource Returns the application message translations component. CApplication
modulePath string Returns the directory that contains the application modules. CModule
modules array Returns the configuration of the currently installed modules. CModule
name string 应用程序名称。默认为 'My Application'。 CApplication
numberFormatter CNumberFormatter the locale-dependent number formatter. CApplication
params CAttributeCollection 返回用户定义的参数。 CModule
parentModule CModule 返回父模块。 CModule
preload array the IDs of the application components that should be preloaded. CModule
request CHttpRequest Returns the request component. CApplication
runtimePath string Returns the directory that stores runtime files. CApplication
securityManager CSecurityManager Returns the security manager component. CApplication
session CHttpSession the session component CWebApplication
sourceLanguage string the language that the application is written in. CApplication
statePersister CStatePersister Returns the state persister component. CApplication
systemViewPath string the root directory of system view files. CWebApplication
theme CTheme the theme used currently. CWebApplication
themeManager CThemeManager the theme manager. CWebApplication
timeZone string Returns the time zone used by this application. CApplication
urlManager CUrlManager Returns the URL manager component. CApplication
user CWebUser the user session information CWebApplication
viewPath string the root directory of view files. CWebApplication
viewRenderer IViewRenderer Returns the view renderer. CWebApplication
widgetFactory IWidgetFactory Returns the widget factory. CWebApplication

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() 构造器。 CApplication
__get() Getter 魔术方法。 CModule
__isset() 检查一个属性值是否为空。 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. CWebApplication
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. CWebApplication
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
clearGlobalState() Clears a global value. CApplication
configure() Configures the module with the specified configuration. CModule
createAbsoluteUrl() Creates an absolute URL based on the given controller and action information. CApplication
createController() Creates a controller instance based on a route. CWebApplication
createUrl() Creates a relative URL based on the given controller and action information. CApplication
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
displayError() Displays the captured PHP error. CApplication
displayException() Displays the uncaught PHP exception. CApplication
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
end() 终止应用程序。 CApplication
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
findLocalizedFile() Returns the localized version of a specified file. CApplication
findModule() Do not call this method. This method is used internally to search for a module by its ID. CWebApplication
getAssetManager() Returns the asset manager component CWebApplication
getAuthManager() Returns the authorization manager component CWebApplication
getBasePath() Returns the root path of the application. CApplication
getBaseUrl() Returns the relative URL for the application. CApplication
getCache() Returns the cache component. CApplication
getClientScript() Returns the client script manager. CWebApplication
getComponent() Retrieves the named application component. CModule
getComponents() 返回应用程序组件。 CModule
getController() Returns the currently active controller CWebApplication
getControllerPath() Returns the directory that contains the controller classes. Defaults to 'protected/controllers'. CWebApplication
getCoreMessages() Returns the core message translations component. CApplication
getDateFormatter() Returns the locale-dependent date formatter. CApplication
getDb() Returns the database connection component. CApplication
getErrorHandler() Returns the error handler component. CApplication
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getExtensionPath() Returns the root directory that holds all third-party extensions. CApplication
getFormat() Returns the formatter component. CApplication
getGlobalState() Returns a global value. CApplication
getHomeUrl() Returns the homepage URL CApplication
getId() 返回应用程序唯一的标识。 CApplication
getLanguage() Returns the language that the user is using and the application should be targeted to. CApplication
getLayoutPath() Returns the root directory of layout files. Defaults to 'protected/views/layouts'. CWebApplication
getLocale() Returns the locale instance. CApplication
getLocaleDataPath() Returns the directory that contains the locale data. CApplication
getMessages() Returns the application message translations component. CApplication
getModule() 检索指定的应用程序模块。 CModule
getModulePath() Returns the directory that contains the application modules. CModule
getModules() Returns the configuration of the currently installed modules. CModule
getNumberFormatter() Returns the locale-dependent number formatter. The current application locale will be used. CApplication
getParams() 返回用户定义的参数。 CModule
getParentModule() 返回父模块。 CModule
getRequest() Returns the request component. CApplication
getRuntimePath() Returns the directory that stores runtime files. CApplication
getSecurityManager() Returns the security manager component. CApplication
getSession() Returns the session component CWebApplication
getStatePersister() Returns the state persister component. CApplication
getSystemViewPath() Returns the root directory of system view files. Defaults to 'protected/views/system'. CWebApplication
getTheme() Returns the theme used currently. Null if no theme is being used. CWebApplication
getThemeManager() Returns the theme manager. CWebApplication
getTimeZone() Returns the time zone used by this application. CApplication
getUrlManager() Returns the URL manager component. CApplication
getUser() Returns the user session information CWebApplication
getViewPath() Returns the root directory of view files. Defaults to 'protected/views'. CWebApplication
getViewRenderer() Returns the view renderer. CWebApplication
getWidgetFactory() Returns the widget factory. CWebApplication
handleError() Handles PHP execution errors such as warnings, notices. CApplication
handleException() Handles uncaught PHP exceptions. CApplication
hasComponent() Checks whether the named component exists. CModule
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasModule() Returns a value indicating whether the specified module is installed. CModule
hasProperty() Determines whether a property is defined. CComponent
loadGlobalState() Loads the global state data from persistent storage. CApplication
onBeginRequest() Raised right BEFORE the application processes the request. CApplication
onEndRequest() Raised right AFTER the application processes the request. CApplication
onError() Raised when a PHP execution error occurs. CApplication
onException() Raised when an uncaught PHP exception occurs. CApplication
processRequest() Processes the current request. CWebApplication
raiseEvent() Raises an event. CComponent
run() 运行应用程序。 CApplication
runController() Creates the controller and performs the specified action. CWebApplication
saveGlobalState() Saves the global state data into persistent storage. CApplication
setAliases() Defines the root aliases. CModule
setBasePath() Sets the root directory of the application. CApplication
setComponent() Puts a component under the management of the module. CModule
setComponents() 设置应用程序组件。 CModule
setController() Sets the currently active controller CWebApplication
setControllerPath() Sets the directory that contains the controller classes. CWebApplication
setExtensionPath() Sets the root directory that holds all third-party extensions. CApplication
setGlobalState() Sets a global value. CApplication
setHomeUrl() Sets the homepage URL CApplication
setId() Sets the unique identifier for the application. CApplication
setImport() 设置用于在模块中使用的别名。 CModule
setLanguage() Specifies which language the application is targeted to. CApplication
setLayoutPath() Sets the root directory of layout files. CWebApplication
setLocaleDataPath() Sets the directory that contains the locale data. CApplication
setModulePath() Sets the directory that contains the application modules. CModule
setModules() Configures the sub-modules of this module. CModule
setParams() 设置用户定义的参数 CModule
setRuntimePath() Sets the directory that stores runtime files. CApplication
setSystemViewPath() Sets the root directory of system view files. CWebApplication
setTheme() Sets the theme name CWebApplication
setTimeZone() Sets the time zone used by this application. CApplication
setViewPath() Sets the root directory of view files. CWebApplication

受保护的方法

隐藏继承的方法

方法描述被定义在
init() Initializes the application. CWebApplication
initSystemHandlers() Initializes the error handlers. CApplication
parseActionParams() Parses a path info into an action ID and GET variables. CWebApplication
preinit() Preinitializes the module. CModule
preloadComponents() 加载静态应用程序组件。 CModule
registerCoreComponents() Registers the core application components. CWebApplication

事件

隐藏继承的事件

事件描述被定义在
onBeginRequest Raised right BEFORE the application processes the request. CApplication
onEndRequest Raised right AFTER the application processes the request. CApplication
onException Raised when an uncaught PHP exception occurs. CApplication
onError Raised when a PHP execution error occurs. CApplication

属性详情

assetManager 属性 只读

the asset manager component

authManager 属性 只读

the authorization manager component

catchAllRequest 属性
public array $catchAllRequest;

the configuration specifying a controller which should handle all user requests. This is mainly used when the application is in maintenance mode and we should use a controller to handle all incoming requests. The configuration specifies the controller route (the first element) and GET parameters (the rest name-value pairs). For example,

array(
    'offline/notice',
    'param1'=>'value1',
    'param2'=>'value2',
)
Defaults to null, meaning catch-all is not effective.

clientScript 属性 只读

Returns the client script manager.

controller 属性
public CController getController()
public void setController(CController $value)

the currently active controller

controllerMap 属性
public array $controllerMap;

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

array(
  'post'=>array(
     'class'=>'path.to.PostController',
     'pageTitle'=>'something new',
  ),
  'user'=>'path.to.UserController',
)


Note, when processing an incoming request, the controller map will first be checked to see if the request can be handled by one of the controllers in the map. If not, a controller will be searched for under the default controller path.

controllerNamespace 属性 (自版本 v1.1.11 可用)
public string $controllerNamespace;

Namespace that should be used when loading controllers. Default is to use global namespace.

controllerPath 属性
public string getControllerPath()
public void setControllerPath(string $value)

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

defaultController 属性
public string $defaultController;

the route of the default controller, action or module. Defaults to 'site'.

layout 属性
public mixed $layout;

the application-wide layout. Defaults to 'main' (relative to layoutPath). If this is false, then no layout will be used.

layoutPath 属性
public string getLayoutPath()
public void setLayoutPath(string $path)

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

session 属性 只读

the session component

systemViewPath 属性
public string getSystemViewPath()
public void setSystemViewPath(string $path)

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

theme 属性
public CTheme getTheme()
public void setTheme(string $value)

the theme used currently. Null if no theme is being used.

themeManager 属性 只读

the theme manager.

user 属性 只读
public CWebUser getUser()

the user session information

viewPath 属性
public string getViewPath()
public void setViewPath(string $path)

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

viewRenderer 属性 只读

Returns the view renderer. If this component is registered and enabled, the default view rendering logic defined in CBaseController will be replaced by this renderer.

widgetFactory 属性 只读 (自版本 v1.1 可用)

Returns the widget factory.

方法详情

afterControllerAction() 方法
public void afterControllerAction(CController $controller, CAction $action)
$controller CController the controller
$action CAction the action
源码: framework/web/CWebApplication.php#514 (显示)
public function 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. You may override this method with logic that needs to be done after all controller actions.

beforeControllerAction() 方法
public boolean beforeControllerAction(CController $controller, CAction $action)
$controller CController the controller
$action CAction the action
{return} boolean whether the action should be executed.
源码: framework/web/CWebApplication.php#501 (显示)
public function beforeControllerAction($controller,$action)
{
    return 
true;
}

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 with logic that needs to be done before all controller actions.

createController() 方法
public array createController(string $route, CWebModule $owner=NULL)
$route string the route of the request.
$owner CWebModule the module that the new controller will belong to. Defaults to null, meaning the application instance is the owner.
{return} array the controller instance and the action ID. Null if the controller class does not exist or the route is invalid.
源码: framework/web/CWebApplication.php#310 (显示)
public function createController($route,$owner=null)
{
    if(
$owner===null)
        
$owner=$this;
    if((array)
$route===$route || ($route=trim($route,'/'))==='')
        
$route=$owner->defaultController;
    
$caseSensitive=$this->getUrlManager()->caseSensitive;

    
$route.='/';
    while((
$pos=strpos($route,'/'))!==false)
    {
        
$id=substr($route,0,$pos);
        if(!
preg_match('/^\w+$/',$id))
            return 
null;
        if(!
$caseSensitive)
            
$id=strtolower($id);
        
$route=(string)substr($route,$pos+1);
        if(!isset(
$basePath))  // first segment
        
{
            if(isset(
$owner->controllerMap[$id]))
            {
                return array(
                    
Yii::createComponent($owner->controllerMap[$id],$id,$owner===$this?null:$owner),
                    
$this->parseActionParams($route),
                );
            }

            if((
$module=$owner->getModule($id))!==null)
                return 
$this->createController($route,$module);

            
$basePath=$owner->getControllerPath();
            
$controllerID='';
        }
        else
            
$controllerID.='/';
        
$className=ucfirst($id).'Controller';
        
$classFile=$basePath.DIRECTORY_SEPARATOR.$className.'.php';

        if(
$owner->controllerNamespace!==null)
            
$className=$owner->controllerNamespace.'\\'.str_replace('/','\\',$controllerID).$className;

        if(
is_file($classFile))
        {
            if(!
class_exists($className,false))
                require(
$classFile);
            if(
class_exists($className,false) && is_subclass_of($className,'CController'))
            {
                
$id[0]=strtolower($id[0]);
                return array(
                    new 
$className($controllerID.$id,$owner===$this?null:$owner),
                    
$this->parseActionParams($route),
                );
            }
            return 
null;
        }
        
$controllerID.=$id;
        
$basePath.=DIRECTORY_SEPARATOR.$id;
    }
}

Creates a controller instance based on a route. The route should contain the controller ID and the action ID. It may also contain additional GET variables. All these must be concatenated together with slashes.

This method will attempt to create a controller in the following order:

  1. If the first segment is found in controllerMap, the corresponding controller configuration will be used to create the controller;
  2. If the first segment is found to be a module ID, the corresponding module will be used to create the controller;
  3. Otherwise, it will search under the controllerPath to create the corresponding controller. For example, if the route is "admin/user/create", then the controller will be created using the class file "protected/controllers/admin/UserController.php".

findModule() 方法
public CWebModule findModule(string $id)
$id string module ID
{return} CWebModule the module that has the specified ID. Null if no module is found.
源码: framework/web/CWebApplication.php#523 (显示)
public function findModule($id)
{
    if((
$controller=$this->getController())!==null && ($module=$controller->getModule())!==null)
    {
        do
        {
            if((
$m=$module->getModule($id))!==null)
                return 
$m;
        } while((
$module=$module->getParentModule())!==null);
    }
    if((
$m=$this->getModule($id))!==null)
        return 
$m;
}

Do not call this method. This method is used internally to search for a module by its ID.

getAssetManager() 方法
public CAssetManager getAssetManager()
{return} CAssetManager the asset manager component
源码: framework/web/CWebApplication.php#191 (显示)
public function getAssetManager()
{
    return 
$this->getComponent('assetManager');
}

getAuthManager() 方法
public IAuthManager getAuthManager()
{return} IAuthManager the authorization manager component
源码: framework/web/CWebApplication.php#183 (显示)
public function getAuthManager()
{
    return 
$this->getComponent('authManager');
}

getClientScript() 方法
public CClientScript getClientScript()
{return} CClientScript the client script manager
源码: framework/web/CWebApplication.php#228 (显示)
public function getClientScript()
{
    return 
$this->getComponent('clientScript');
}

Returns the client script manager.

getController() 方法
public CController getController()
{return} CController the currently active controller
源码: framework/web/CWebApplication.php#391 (显示)
public function getController()
{
    return 
$this->_controller;
}

getControllerPath() 方法
public string getControllerPath()
{return} string the directory that contains the controller classes. Defaults to 'protected/controllers'.
源码: framework/web/CWebApplication.php#407 (显示)
public function getControllerPath()
{
    if(
$this->_controllerPath!==null)
        return 
$this->_controllerPath;
    else
        return 
$this->_controllerPath=$this->getBasePath().DIRECTORY_SEPARATOR.'controllers';
}

getLayoutPath() 方法
public string getLayoutPath()
{return} string the root directory of layout files. Defaults to 'protected/views/layouts'.
源码: framework/web/CWebApplication.php#473 (显示)
public function getLayoutPath()
{
    if(
$this->_layoutPath!==null)
        return 
$this->_layoutPath;
    else
        return 
$this->_layoutPath=$this->getViewPath().DIRECTORY_SEPARATOR.'layouts';
}

getSession() 方法
public CHttpSession getSession()
{return} CHttpSession the session component
源码: framework/web/CWebApplication.php#199 (显示)
public function getSession()
{
    return 
$this->getComponent('session');
}

getSystemViewPath() 方法
public string getSystemViewPath()
{return} string the root directory of system view files. Defaults to 'protected/views/system'.
源码: framework/web/CWebApplication.php#451 (显示)
public function getSystemViewPath()
{
    if(
$this->_systemViewPath!==null)
        return 
$this->_systemViewPath;
    else
        return 
$this->_systemViewPath=$this->getViewPath().DIRECTORY_SEPARATOR.'system';
}

getTheme() 方法
public CTheme getTheme()
{return} CTheme the theme used currently. Null if no theme is being used.
源码: framework/web/CWebApplication.php#254 (显示)
public function getTheme()
{
    if(
is_string($this->_theme))
        
$this->_theme=$this->getThemeManager()->getTheme($this->_theme);
    return 
$this->_theme;
}

getThemeManager() 方法
public CThemeManager getThemeManager()
{return} CThemeManager the theme manager.
源码: framework/web/CWebApplication.php#246 (显示)
public function getThemeManager()
{
    return 
$this->getComponent('themeManager');
}

getUser() 方法
public CWebUser getUser()
{return} CWebUser the user session information
源码: framework/web/CWebApplication.php#207 (显示)
public function getUser()
{
    return 
$this->getComponent('user');
}

getViewPath() 方法
public string getViewPath()
{return} string the root directory of view files. Defaults to 'protected/views'.
源码: framework/web/CWebApplication.php#429 (显示)
public function getViewPath()
{
    if(
$this->_viewPath!==null)
        return 
$this->_viewPath;
    else
        return 
$this->_viewPath=$this->getBasePath().DIRECTORY_SEPARATOR.'views';
}

getViewRenderer() 方法
public IViewRenderer getViewRenderer()
{return} IViewRenderer the view renderer.
源码: framework/web/CWebApplication.php#219 (显示)
public function getViewRenderer()
{
    return 
$this->getComponent('viewRenderer');
}

Returns the view renderer. If this component is registered and enabled, the default view rendering logic defined in CBaseController will be replaced by this renderer.

getWidgetFactory() 方法 (自版本 v1.1 可用)
public IWidgetFactory getWidgetFactory()
{return} IWidgetFactory the widget factory
源码: framework/web/CWebApplication.php#238 (显示)
public function getWidgetFactory()
{
    return 
$this->getComponent('widgetFactory');
}

Returns the widget factory.

init() 方法
protected void init()
源码: framework/web/CWebApplication.php#541 (显示)
protected function init()
{
    
parent::init();
    
// preload 'request' so that it has chance to respond to onBeginRequest event.
    
$this->getRequest();
}

Initializes the application. This method overrides the parent implementation by preloading the 'request' component.

parseActionParams() 方法
protected string parseActionParams(string $pathInfo)
$pathInfo string path info
{return} string action ID
源码: framework/web/CWebApplication.php#375 (显示)
protected function parseActionParams($pathInfo)
{
    if((
$pos=strpos($pathInfo,'/'))!==false)
    {
        
$manager=$this->getUrlManager();
        
$manager->parsePathInfo((string)substr($pathInfo,$pos+1));
        
$actionID=substr($pathInfo,0,$pos);
        return 
$manager->caseSensitive $actionID strtolower($actionID);
    }
    else
        return 
$pathInfo;
}

Parses a path info into an action ID and GET variables.

processRequest() 方法
public void processRequest()
源码: framework/web/CWebApplication.php#131 (显示)
public function processRequest()
{
    if(
is_array($this->catchAllRequest) && isset($this->catchAllRequest[0]))
    {
        
$route=$this->catchAllRequest[0];
        foreach(
array_splice($this->catchAllRequest,1) as $name=>$value)
            
$_GET[$name]=$value;
    }
    else
        
$route=$this->getUrlManager()->parseUrl($this->getRequest());
    
$this->runController($route);
}

Processes the current request. It first resolves the request into controller and action, and then creates the controller to perform the action.

registerCoreComponents() 方法
protected void registerCoreComponents()
源码: framework/web/CWebApplication.php#149 (显示)
protected function registerCoreComponents()
{
    
parent::registerCoreComponents();

    
$components=array(
        
'session'=>array(
            
'class'=>'CHttpSession',
        ),
        
'assetManager'=>array(
            
'class'=>'CAssetManager',
        ),
        
'user'=>array(
            
'class'=>'CWebUser',
        ),
        
'themeManager'=>array(
            
'class'=>'CThemeManager',
        ),
        
'authManager'=>array(
            
'class'=>'CPhpAuthManager',
        ),
        
'clientScript'=>array(
            
'class'=>'CClientScript',
        ),
        
'widgetFactory'=>array(
            
'class'=>'CWidgetFactory',
        ),
    );

    
$this->setComponents($components);
}

Registers the core application components. This method overrides the parent implementation by registering additional core components.

参见

runController() 方法
public void runController(string $route)
$route string the route of the current request. See createController for more details.
源码: framework/web/CWebApplication.php#274 (显示)
public function runController($route)
{
    if((
$ca=$this->createController($route))!==null)
    {
        list(
$controller,$actionID)=$ca;
        
$oldController=$this->_controller;
        
$this->_controller=$controller;
        
$controller->init();
        
$controller->run($actionID);
        
$this->_controller=$oldController;
    }
    else
        throw new 
CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',
            array(
'{route}'=>$route===''?$this->defaultController:$route)));
}

Creates the controller and performs the specified action.

setController() 方法
public void setController(CController $value)
$value CController the currently active controller
源码: framework/web/CWebApplication.php#399 (显示)
public function setController($value)
{
    
$this->_controller=$value;
}

setControllerPath() 方法
public void setControllerPath(string $value)
$value string the directory that contains the controller classes.
源码: framework/web/CWebApplication.php#419 (显示)
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() 方法
public void setLayoutPath(string $path)
$path string the root directory of layout files.
源码: framework/web/CWebApplication.php#485 (显示)
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)));
}

setSystemViewPath() 方法
public void setSystemViewPath(string $path)
$path string the root directory of system view files.
源码: framework/web/CWebApplication.php#463 (显示)
public function setSystemViewPath($path)
{
    if((
$this->_systemViewPath=realpath($path))===false || !is_dir($this->_systemViewPath))
        throw new 
CException(Yii::t('yii','The system view path "{path}" is not a valid directory.',
            array(
'{path}'=>$path)));
}

setTheme() 方法
public void setTheme(string $value)
$value string the theme name
源码: framework/web/CWebApplication.php#264 (显示)
public function setTheme($value)
{
    
$this->_theme=$value;
}

setViewPath() 方法
public void setViewPath(string $path)
$path string the root directory of view files.
源码: framework/web/CWebApplication.php#441 (显示)
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)));
}