Yii Framework v1.1.10 绫诲弬鑰

CWebApplication

system.web
缁ф壙 class CWebApplication » CApplication » CModule » CComponent
婧愯嚜 1.0
鐗堟湰 $Id: CWebApplication.php 3515 2011-12-28 12:29:24Z mdomba $
婧愮爜 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 杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆 CApplication
baseUrl string 杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 CApplication
behaviors array the behaviors that should be attached to the module. CModule
cache CCache 杩斿洖缂撳瓨缁勪欢銆 CApplication
catchAllRequest array the configuration specifying a controller which should handle all user requests. CWebApplication
charset string 搴旂敤绋嬪簭褰撳墠浣跨敤鐨勫瓧绗﹂泦銆傞粯璁や负鈥楿TF-8鈥欍 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
controllerPath string the directory that contains the controller classes. CWebApplication
coreMessages CPhpMessageSource 杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆 CApplication
dateFormatter CDateFormatter 杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆 CApplication
db CDbConnection 杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲 CApplication
defaultController string the route of the default controller, action or module. CWebApplication
errorHandler CErrorHandler 杩斿洖閿欒澶勭悊缁勪欢銆 CApplication
extensionPath string 杩斿洖绗笁鏂规墿灞曟牴鐩綍銆 CApplication
homeUrl string 涓婚〉URL CApplication
id string 杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺ CApplication
language string 杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆 CApplication
layout mixed the application-wide layout. CWebApplication
layoutPath string the root directory of layout files. CWebApplication
locale CLocale 杩斿洖鏈湴锛堢幆澧冿級瀹炰緥銆 CApplication
localeDataPath string 杩斿洖鍖呭惈鏈湴鍖栫殑鏁版嵁鐩綍銆 CApplication
messages CMessageSource 杩斿洖搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢銆 CApplication
modulePath string 杩斿洖鍖呭惈搴旂敤绋嬪簭妯″潡鐨勭洰褰曘 CModule
modules array 杩斿洖搴旂敤绋嬪簭褰撳墠宸茬粡瀹夎鐨勬ā鍧椼 CModule
name string 搴旂敤绋嬪簭鍚嶅瓧銆傞粯璁や负鈥楳y Application鈥欍 CApplication
numberFormatter CNumberFormatter 鏈湴鍖栨暟瀛楁牸寮忋 灏嗕娇鐢ㄥ綋鍓application locale CApplication
params CAttributeCollection 杩斿洖鐢ㄦ埛瀹氫箟鐨勫弬鏁般 CModule
parentModule CModule 杩斿洖鐖舵ā鍧椼 CModule
preload array the IDs of the application components that should be preloaded. CModule
request CHttpRequest 杩斿洖璇锋眰缁勪欢銆 CApplication
runtimePath string 杩斿洖瀛樺偍杩愯鏃舵枃浠剁洰褰曘 CApplication
securityManager CSecurityManager 杩斿洖瀹夊叏绠$悊鍣ㄧ粍浠躲 CApplication
session CHttpSession the session component CWebApplication
sourceLanguage string 搴旂敤绋嬪簭浣跨敤璇█. CApplication
statePersister CStatePersister 杩斿洖鎸佷箙鐘舵佺粍浠躲 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 杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 CApplication
urlManager CUrlManager 杩斿洖URL绠$悊鍣ㄧ粍浠躲 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() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犲櫒銆 CApplication
__get() getter榄旀湳鏂规硶銆 CModule
__isset() 妫鏌ヤ竴涓睘鎬у兼槸鍚︿负null銆 CModule
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
afterControllerAction() The post-filter for controller actions. CWebApplication
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
beforeControllerAction() The pre-filter for controller actions. CWebApplication
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
clearGlobalState() 娓呯┖涓涓叏灞鍊笺 CApplication
configure() 涓烘ā鍧楁寚瀹氶厤缃 CModule
createAbsoluteUrl() 鍒涘缓涓涓熀浜庣粰瀹氭帶鍒跺櫒鍜屽姩浣滐紙淇℃伅锛夌粷瀵圭殑URL銆 CApplication
createController() Creates a controller instance based on a route. CWebApplication
createUrl() 鍒涘缓涓涓熀浜庣粰瀹氭帶鍒跺櫒鍜屽姩浣滐紙淇℃伅锛夌浉瀵圭殑URL銆 CApplication
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
displayError() 鏄剧ず鎹曡幏鐨凱HP閿欒銆 CApplication
displayException() 鏄剧ず鏈崟鑾风殑PHP寮傚父銆 CApplication
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
end() 缁堟搴旂敤绋嬪簭銆 CApplication
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
findLocalizedFile() 杩斿洖鎸囧畾鏂囦欢鐨勬湰鍦板寲鐗堟湰銆 CApplication
findModule() Do not call this method. This method is used internally to search for a module by its ID. CWebApplication
getAssetManager() 杩斿洖the asset manager component CWebApplication
getAuthManager() 杩斿洖the authorization manager component CWebApplication
getBasePath() 杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆 CApplication
getBaseUrl() 杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 CApplication
getCache() 杩斿洖缂撳瓨缁勪欢銆 CApplication
getClientScript() Returns the client script manager. CWebApplication
getComponent() Retrieves the named application component. CModule
getComponents() 杩斿洖搴旂敤缁勪欢銆 CModule
getController() 杩斿洖the currently active controller CWebApplication
getControllerPath() 杩斿洖the directory that contains the controller classes. Defaults to 'protected/controllers'. CWebApplication
getCoreMessages() 杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆 CApplication
getDateFormatter() 杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆 CApplication
getDb() 杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲 CApplication
getErrorHandler() 杩斿洖閿欒澶勭悊缁勪欢銆 CApplication
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getExtensionPath() 杩斿洖绗笁鏂规墿灞曟牴鐩綍銆 CApplication
getGlobalState() 杩斿洖涓涓叏灞鍊 CApplication
getHomeUrl() 杩斿洖涓婚〉URL CApplication
getId() 杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺ CApplication
getLanguage() 杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆 CApplication
getLayoutPath() 杩斿洖the root directory of layout files. Defaults to 'protected/views/layouts'. CWebApplication
getLocale() 杩斿洖鏈湴锛堢幆澧冿級瀹炰緥銆 CApplication
getLocaleDataPath() 杩斿洖鍖呭惈鏈湴鍖栫殑鏁版嵁鐩綍銆 CApplication
getMessages() 杩斿洖搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢銆 CApplication
getModule() 妫绱㈡寚瀹氱殑搴旂敤妯″潡銆 CModule
getModulePath() 杩斿洖鍖呭惈搴旂敤绋嬪簭妯″潡鐨勭洰褰曘 CModule
getModules() 杩斿洖搴旂敤绋嬪簭褰撳墠宸茬粡瀹夎鐨勬ā鍧椼 CModule
getNumberFormatter() 杩斿洖鏈湴鍖栨暟瀛楁牸寮忋 灏嗕娇鐢ㄥ綋鍓application locale CApplication
getParams() 杩斿洖鐢ㄦ埛瀹氫箟鐨勫弬鏁般 CModule
getParentModule() 杩斿洖鐖舵ā鍧椼 CModule
getRequest() 杩斿洖璇锋眰缁勪欢銆 CApplication
getRuntimePath() 杩斿洖瀛樺偍杩愯鏃舵枃浠剁洰褰曘 CApplication
getSecurityManager() 杩斿洖瀹夊叏绠$悊鍣ㄧ粍浠躲 CApplication
getSession() 杩斿洖the session component CWebApplication
getStatePersister() 杩斿洖鎸佷箙鐘舵佺粍浠躲 CApplication
getSystemViewPath() 杩斿洖the root directory of system view files. Defaults to 'protected/views/system'. CWebApplication
getTheme() 杩斿洖the theme used currently. Null if no theme is being used. CWebApplication
getThemeManager() 杩斿洖the theme manager. CWebApplication
getTimeZone() 杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 CApplication
getUrlManager() 杩斿洖URL绠$悊鍣ㄧ粍浠躲 CApplication
getUser() 杩斿洖the user session information CWebApplication
getViewPath() 杩斿洖the root directory of view files. Defaults to 'protected/views'. CWebApplication
getViewRenderer() Returns the view renderer. CWebApplication
getWidgetFactory() Returns the widget factory. CWebApplication
handleError() 澶勭悊PHP寮傚父閿欒锛屽璀﹀憡锛岄氱煡銆 CApplication
handleException() 澶勭悊鏈崟鑾风殑PHP寮傚父銆 CApplication
hasComponent() 妫鏌ユ槸鍚﹀瓨鍦ㄦ寚瀹氱粍浠躲 CModule
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasModule() 妫鏌ユ槸鍚﹀凡缁忓畨瑁呬簡鎸囧畾妯″潡銆 CModule
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
loadGlobalState() 浠庢寔涔呭瓨鍌ㄥ姞杞藉叏灞鐘舵佹暟鎹 CApplication
onBeginRequest() 搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪墠鍙戣捣銆 CApplication
onEndRequest() 搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪悗鍙戣捣銆 CApplication
onError() 褰撲竴涓狿HP寮傚父閿欒鍙戠敓鏃跺彂璧枫 CApplication
onException() 褰撲竴涓湭鎹曡幏鐨凱HP寮傚父鍙戠敓鏃跺彂璧枫 CApplication
processRequest() Processes the current request. CWebApplication
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
run() 杩愯搴旂敤绋嬪簭銆 CApplication
runController() Creates the controller and performs the specified action. CWebApplication
saveGlobalState() 淇濆瓨鍏ㄥ眬鐘舵佹暟鎹埌鎸佷箙瀛樺偍銆 CApplication
setAliases() 瀹氫箟鏍圭洰褰曠殑鍒悕銆 CModule
setBasePath() 璁剧疆搴旂敤绋嬪簭鏍圭洰褰曘 CApplication
setComponent() 娣诲姞涓涓粍浠跺埌妯″潡涓 CModule
setComponents() 璁剧疆搴旂敤缁勪欢銆 CModule
setController() 璁剧疆the currently active controller CWebApplication
setControllerPath() 璁剧疆the directory that contains the controller classes. CWebApplication
setExtensionPath() 璁剧疆绗笁鏂规墿灞曠洰褰曘 CApplication
setGlobalState() 璁剧疆涓涓叏灞鍊笺 CApplication
setHomeUrl() 璁剧疆璁剧疆涓婚〉URL CApplication
setId() 璁剧疆搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆 CApplication
setImport() 璁剧疆鍦ㄦā鍧椾腑浣跨敤鐨勮矾寰勫埆鍚嶃 CModule
setLanguage() 鎸囧畾搴旂敤绋嬪簭璇█銆 CApplication
setLayoutPath() 璁剧疆the root directory of layout files. CWebApplication
setLocaleDataPath() 璁剧疆鍖呭惈鏈湴鍖栨暟鎹殑鐩綍銆 CApplication
setModulePath() 璁剧疆鍖呭惈搴旂敤绋嬪簭妯″潡鐨勭洰褰曘 CModule
setModules() 閰嶇疆妯″潡鐨勫瓙妯″潡銆 CModule
setParams() 璁剧疆鐢ㄦ埛瀹氫箟鐨勫弬鏁般 CModule
setRuntimePath() 璁剧疆瀛樺偍杩愯鏃舵枃浠剁洰褰曘 CApplication
setSystemViewPath() 璁剧疆the root directory of system view files. CWebApplication
setTheme() 璁剧疆the theme name CWebApplication
setTimeZone() 璁剧疆搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 CApplication
setViewPath() 璁剧疆the root directory of view files. CWebApplication

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
init() Initializes the application. CWebApplication
initSystemHandlers() 鍒濆鍖栫被鑷姩鍔犺浇鍣ㄥ拰閿欒澶勭悊銆 CApplication
parseActionParams() Parses a path info into an action ID and GET variables. CWebApplication
preinit() 妯″潡棰勫垵濮嬪寲銆 CModule
preloadComponents() 鍔犺浇闈欐佸簲鐢ㄧ粍浠躲 CModule
registerCoreComponents() Registers the core application components. CWebApplication

浜嬩欢

闅愯棌缁ф壙浜嬩欢

浜嬩欢鎻忚堪瀹氫箟鍦
onBeginRequest 搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪墠鍙戣捣銆 CApplication
onEndRequest 搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪悗鍙戣捣銆 CApplication
onException 褰撲竴涓湭鎹曡幏鐨凱HP寮傚父鍙戠敓鏃跺彂璧枫 CApplication
onError 褰撲竴涓狿HP寮傚父閿欒鍙戠敓鏃跺彂璧枫 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.

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#504 (鏄剧ず)
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#491 (鏄剧ず)
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#304 (鏄剧ず)
public function createController($route,$owner=null)
{
    if(
$owner===null)
        
$owner=$this;
    if((
$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(
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#513 (鏄剧ず)
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#185 (鏄剧ず)
public function getAssetManager()
{
    return 
$this->getComponent('assetManager');
}

getAuthManager() 鏂规硶
public IAuthManager getAuthManager()
{return} IAuthManager the authorization manager component
婧愮爜锛 framework/web/CWebApplication.php#177 (鏄剧ず)
public function getAuthManager()
{
    return 
$this->getComponent('authManager');
}

getClientScript() 鏂规硶
public CClientScript getClientScript()
{return} CClientScript the client script manager
婧愮爜锛 framework/web/CWebApplication.php#222 (鏄剧ず)
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#381 (鏄剧ず)
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#397 (鏄剧ず)
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#463 (鏄剧ず)
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#193 (鏄剧ず)
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#441 (鏄剧ず)
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#248 (鏄剧ず)
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#240 (鏄剧ず)
public function getThemeManager()
{
    return 
$this->getComponent('themeManager');
}

getUser() 鏂规硶
public CWebUser getUser()
{return} CWebUser the user session information
婧愮爜锛 framework/web/CWebApplication.php#201 (鏄剧ず)
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#419 (鏄剧ず)
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#213 (鏄剧ず)
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#232 (鏄剧ず)
public function getWidgetFactory()
{
    return 
$this->getComponent('widgetFactory');
}

Returns the widget factory.

init() 鏂规硶
protected void init()
婧愮爜锛 framework/web/CWebApplication.php#531 (鏄剧ず)
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#365 (鏄剧ず)
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#125 (鏄剧ず)
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#143 (鏄剧ず)
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#268 (鏄剧ず)
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#389 (鏄剧ず)
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#409 (鏄剧ず)
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#475 (鏄剧ず)
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#453 (鏄剧ず)
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#258 (鏄剧ず)
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#431 (鏄剧ず)
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)));
}

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.