Yii Framework v1.1.10 绫诲弬鑰

CApplication

system.base
缁ф壙 abstract class CApplication » CModule » CComponent
瀛愮被 CConsoleApplication, CWebApplication
婧愯嚜 1.0
鐗堟湰 $Id: CApplication.php 3515 2011-12-28 12:29:24Z mdomba $
婧愮爜 framework/base/CApplication.php
CApplication鏄墍鏈夊簲鐢ㄧ▼搴忕被鐨勫熀绫汇

涓涓簲鐢ㄧ▼搴忔湇鍔″湪鐢ㄦ埛璇锋眰澶勭悊鐨勫叏灞鑼冨洿鍐呫 瀹冭礋璐d负鏁翠釜搴旂敤绋嬪簭绠$悊 鎻愪緵鍏蜂綋鍔熻兘鐨勫簲鐢ㄧ▼搴忕粍浠躲

CApplication鎵鎻愪緵鐨勬牳蹇冨簲鐢ㄧ粍浠跺涓嬶細
  • errorHandler: 澶勭悊PHP閿欒鍜岄敊璇紓甯搞 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
  • securityManager: 鎻愪緵瀹夊叏鐩稿叧鐨勬湇鍔★紝 渚嬪锛屽搱甯岋紝鍔犲瘑鍔熻兘銆 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
  • statePersister: 鎻愪緵鍏ㄥ眬鐨勬寔涔呯姸鎬佹柟娉曘 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
  • cache: 鎻愪緵缂撳瓨鍔熻兘銆 杩欎釜搴旂敤缁勪欢榛樿鏄姝㈢殑銆
  • messages: 涓虹炕璇戝簲鐢ㄧ▼搴忎俊鎭彁渚涗俊鎭簮銆 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
  • coreMessages: 涓虹炕璇慪ii妗嗘灦淇℃伅鎻愪緵淇℃伅婧愶紝 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐


褰撳鐞嗙敤鎴疯姹傛椂锛孋Application灏嗙粡鍘嗗涓嬬殑鐢熷懡鍛ㄦ湡锛
  1. 鍔犺浇搴旂敤绋嬪簭閰嶇疆锛
  2. 璁剧疆绫昏嚜鍔ㄥ姞杞藉櫒鍜岄敊璇鐞嗭紱
  3. 鍔犺浇闈欐佸簲鐢ㄧ粍浠讹紱
  4. onBeginRequest: 澶勭悊鐢ㄦ埛璇锋眰鍓嶏紱
  5. processRequest: 澶勭悊鐢ㄦ埛璇锋眰鍓嶏紱
  6. onEndRequest: 鐢ㄦ埛璇锋眰鍚庡鐞嗭紙鎴栧悗缃鐞嗙敤鎴疯姹傦級锛


浠庣敓鍛藉懆鏈熺3姝ュ紑濮嬶紝濡傛灉鍙戠敓涓涓狿HP閿欒鎴栭敊璇紓甯革紝 搴旂敤绋嬪簭灏嗗垏鎹㈠埌瀹冪殑閿欒澶勭悊閫昏緫锛屽苟璺冲埌绗6姝ヤ箣鍚庛

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
basePath string 杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆 CApplication
baseUrl string 杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 CApplication
behaviors array the behaviors that should be attached to the module. CModule
cache CCache 杩斿洖缂撳瓨缁勪欢銆 CApplication
charset string 搴旂敤绋嬪簭褰撳墠浣跨敤鐨勫瓧绗﹂泦銆傞粯璁や负鈥楿TF-8鈥欍 CApplication
components array 杩斿洖搴旂敤缁勪欢銆 CModule
controller CController 褰撳墠娲诲姩鎺у埗鍣ㄣ備负Null杩斿洖瀹冪殑鍩虹被銆 CApplication
coreMessages CPhpMessageSource 杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆 CApplication
dateFormatter CDateFormatter 杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆 CApplication
db CDbConnection 杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲 CApplication
errorHandler CErrorHandler 杩斿洖閿欒澶勭悊缁勪欢銆 CApplication
extensionPath string 杩斿洖绗笁鏂规墿灞曟牴鐩綍銆 CApplication
homeUrl string 涓婚〉URL CApplication
id string 杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺ CApplication
language string 杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆 CApplication
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
sourceLanguage string 搴旂敤绋嬪簭浣跨敤璇█. CApplication
statePersister CStatePersister 杩斿洖鎸佷箙鐘舵佺粍浠躲 CApplication
timeZone string 杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 CApplication
urlManager CUrlManager 杩斿洖URL绠$悊鍣ㄧ粍浠躲 CApplication

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犲櫒銆 CApplication
__get() getter榄旀湳鏂规硶銆 CModule
__isset() 妫鏌ヤ竴涓睘鎬у兼槸鍚︿负null銆 CModule
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
clearGlobalState() 娓呯┖涓涓叏灞鍊笺 CApplication
configure() 涓烘ā鍧楁寚瀹氶厤缃 CModule
createAbsoluteUrl() 鍒涘缓涓涓熀浜庣粰瀹氭帶鍒跺櫒鍜屽姩浣滐紙淇℃伅锛夌粷瀵圭殑URL銆 CApplication
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
getBasePath() 杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆 CApplication
getBaseUrl() 杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 CApplication
getCache() 杩斿洖缂撳瓨缁勪欢銆 CApplication
getComponent() Retrieves the named application component. CModule
getComponents() 杩斿洖搴旂敤缁勪欢銆 CModule
getController() 杩斿洖褰撳墠娲诲姩鎺у埗鍣ㄣ備负Null杩斿洖瀹冪殑鍩虹被銆 CApplication
getCoreMessages() 杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆 CApplication
getDateFormatter() 杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆 CApplication
getDb() 杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲 CApplication
getErrorHandler() 杩斿洖閿欒澶勭悊缁勪欢銆 CApplication
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getExtensionPath() 杩斿洖绗笁鏂规墿灞曟牴鐩綍銆 CApplication
getGlobalState() 杩斿洖涓涓叏灞鍊 CApplication
getHomeUrl() 杩斿洖涓婚〉URL CApplication
getId() 杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺ CApplication
getLanguage() 杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆 CApplication
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
getStatePersister() 杩斿洖鎸佷箙鐘舵佺粍浠躲 CApplication
getTimeZone() 杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 CApplication
getUrlManager() 杩斿洖URL绠$悊鍣ㄧ粍浠躲 CApplication
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() 澶勭悊璇锋眰銆 CApplication
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
run() 杩愯搴旂敤绋嬪簭銆 CApplication
saveGlobalState() 淇濆瓨鍏ㄥ眬鐘舵佹暟鎹埌鎸佷箙瀛樺偍銆 CApplication
setAliases() 瀹氫箟鏍圭洰褰曠殑鍒悕銆 CModule
setBasePath() 璁剧疆搴旂敤绋嬪簭鏍圭洰褰曘 CApplication
setComponent() 娣诲姞涓涓粍浠跺埌妯″潡涓 CModule
setComponents() 璁剧疆搴旂敤缁勪欢銆 CModule
setExtensionPath() 璁剧疆绗笁鏂规墿灞曠洰褰曘 CApplication
setGlobalState() 璁剧疆涓涓叏灞鍊笺 CApplication
setHomeUrl() 璁剧疆璁剧疆涓婚〉URL CApplication
setId() 璁剧疆搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆 CApplication
setImport() 璁剧疆鍦ㄦā鍧椾腑浣跨敤鐨勮矾寰勫埆鍚嶃 CModule
setLanguage() 鎸囧畾搴旂敤绋嬪簭璇█銆 CApplication
setLocaleDataPath() 璁剧疆鍖呭惈鏈湴鍖栨暟鎹殑鐩綍銆 CApplication
setModulePath() 璁剧疆鍖呭惈搴旂敤绋嬪簭妯″潡鐨勭洰褰曘 CModule
setModules() 閰嶇疆妯″潡鐨勫瓙妯″潡銆 CModule
setParams() 璁剧疆鐢ㄦ埛瀹氫箟鐨勫弬鏁般 CModule
setRuntimePath() 璁剧疆瀛樺偍杩愯鏃舵枃浠剁洰褰曘 CApplication
setTimeZone() 璁剧疆搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 CApplication

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
init() 鍒濆鍖栨ā鍧椼 CModule
initSystemHandlers() 鍒濆鍖栫被鑷姩鍔犺浇鍣ㄥ拰閿欒澶勭悊銆 CApplication
preinit() 妯″潡棰勫垵濮嬪寲銆 CModule
preloadComponents() 鍔犺浇闈欐佸簲鐢ㄧ粍浠躲 CModule
registerCoreComponents() 娉ㄥ唽鏍稿績搴旂敤缁勪欢銆 CApplication

浜嬩欢

闅愯棌缁ф壙浜嬩欢

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

灞炴ц缁

basePath 灞炴
public string getBasePath()
public void setBasePath(string $path)

杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆

baseUrl 灞炴 鍙
public string getBaseUrl(boolean $absolute=false)

杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 蹇嵎鏂规硶灏辨槸CHttpRequest::getBaseUrl()

cache 灞炴 鍙
public CCache getCache()

杩斿洖缂撳瓨缁勪欢銆

charset 灞炴
public string $charset;

搴旂敤绋嬪簭褰撳墠浣跨敤鐨勫瓧绗﹂泦銆傞粯璁や负鈥楿TF-8鈥欍

controller 灞炴 鍙 锛堝彲鐢ㄨ嚜 v1.1.8锛

褰撳墠娲诲姩鎺у埗鍣ㄣ備负Null杩斿洖瀹冪殑鍩虹被銆

coreMessages 灞炴 鍙

杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆

dateFormatter 灞炴 鍙

杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆

db 灞炴 鍙

杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲

errorHandler 灞炴 鍙

杩斿洖閿欒澶勭悊缁勪欢銆

extensionPath 灞炴
public string getExtensionPath()
public void setExtensionPath(string $path)

杩斿洖绗笁鏂规墿灞曟牴鐩綍銆

homeUrl 灞炴
public string getHomeUrl()
public void setHomeUrl(string $value)

涓婚〉URL

id 灞炴
public string getId()
public void setId(string $id)

杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺

language 灞炴
public string getLanguage()
public void setLanguage(string $language)

杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆

locale 灞炴 鍙
public CLocale getLocale(string $localeID=NULL)

杩斿洖鏈湴锛堢幆澧冿級瀹炰緥銆

localeDataPath 灞炴 锛堝彲鐢ㄨ嚜 v1.1.0锛
public string getLocaleDataPath()
public void setLocaleDataPath(string $value)

杩斿洖鍖呭惈鏈湴鍖栫殑鏁版嵁鐩綍銆

messages 灞炴 鍙

杩斿洖搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢銆

name 灞炴
public string $name;

搴旂敤绋嬪簭鍚嶅瓧銆傞粯璁や负鈥楳y Application鈥欍

numberFormatter 灞炴 鍙

鏈湴鍖栨暟瀛楁牸寮忋 灏嗕娇鐢ㄥ綋鍓application locale

request 灞炴 鍙

杩斿洖璇锋眰缁勪欢銆

runtimePath 灞炴
public string getRuntimePath()
public void setRuntimePath(string $path)

杩斿洖瀛樺偍杩愯鏃舵枃浠剁洰褰曘

securityManager 灞炴 鍙

杩斿洖瀹夊叏绠$悊鍣ㄧ粍浠躲

sourceLanguage 灞炴
public string $sourceLanguage;

搴旂敤绋嬪簭浣跨敤璇█. 杩欎釜璇█涓昏鎸囦俊鎭拰瑙嗗浘鏂囦欢涓殑璇█銆 榛樿鏄榚n_us鈥欙紙US English锛夈

statePersister 灞炴 鍙

杩斿洖鎸佷箙鐘舵佺粍浠躲

timeZone 灞炴
public string getTimeZone()
public void setTimeZone(string $value)

杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 杩欎釜涓涓畝鍗曠殑PHP鍑芥暟date_default_timezone_get()鐨勫皝瑁呫

urlManager 灞炴 鍙

杩斿洖URL绠$悊鍣ㄧ粍浠躲

鏂规硶璇︾粏

__construct() 鏂规硶
public void __construct(mixed $config=NULL)
$config mixed 搴旂敤绋嬪簭閰嶇疆銆 濡傛灉鏄竴涓瓧绗︿覆锛屽畠灏嗚褰撲綔鍖呭惈閰嶇疆鐨勬枃浠惰矾寰勶紱 濡傛灉鏄竴涓暟缁勶紝瀹冨皢琚綋浣滃叿浣撶殑閰嶇疆淇℃伅锛 浣犵‘淇濆湪閰嶇疆鏂囦欢涓寚瀹basePath灞炴э紝 瀹冮氬父搴旇鎸囧悜鍚墍鏈夌殑搴旂敤绋嬪簭閫昏緫銆佹ā鏉垮拰鏁版嵁鐨勭洰褰曞寘銆 濡傛灉娌℃湁锛岄偅涔堥粯璁ゅ皢鎸囧畾涓衡榩rotected鈥欑洰褰曘
婧愮爜锛 framework/base/CApplication.php#121 (鏄剧ず)
public function __construct($config=null)
{
    
Yii::setApplication($this);

    
// set basePath at early as possible to avoid trouble
    
if(is_string($config))
        
$config=require($config);
    if(isset(
$config['basePath']))
    {
        
$this->setBasePath($config['basePath']);
        unset(
$config['basePath']);
    }
    else
        
$this->setBasePath('protected');
    
Yii::setPathOfAlias('application',$this->getBasePath());
    
Yii::setPathOfAlias('webroot',dirname($_SERVER['SCRIPT_FILENAME']));
    
Yii::setPathOfAlias('ext',$this->getBasePath().DIRECTORY_SEPARATOR.'extensions');

    
$this->preinit();

    
$this->initSystemHandlers();
    
$this->registerCoreComponents();

    
$this->configure($config);
    
$this->attachBehaviors($this->behaviors);
    
$this->preloadComponents();

    
$this->init();
}

鏋勯犲櫒銆

clearGlobalState() 鏂规硶
public void clearGlobalState(string $key)
$key string 瑕佹竻闄ょ殑鍊肩殑鍚嶇О
婧愮爜锛 framework/base/CApplication.php#639 (鏄剧ず)
public function clearGlobalState($key)
{
    
$this->setGlobalState($key,true,true);
}

娓呯┖涓涓叏灞鍊笺

琚竻闄ょ殑鍊煎湪杩欐璇锋眰鎴栭殢鍚庣殑璇锋眰涓笉鍙娇鐢ㄣ

createAbsoluteUrl() 鏂规硶
public string createAbsoluteUrl(string $route, array $params=array ( ), string $schema='', string $ampersand='&')
$route string URL璺敱銆傚畠鐨勬牸寮忓簲璇ユ槸锛氣楥ontrollerID/ActionID鈥欍
$params array 闄勫姞鐨凣ET鍙傛暟锛坣ame=>value锛夈傚悕绉板拰鍊间細琚玌RL-encoded锛圲RL缂栫爜锛夈
$schema string 瑕佷娇鐢ㄧ殑妯″紡锛堜緥濡傦細 http锛宧ttps锛夈傚鏋滀负绌猴紝schema浣跨敤褰撳墠璇锋眰浣跨敤鐨勬ā寮忋
$ampersand string URL涓璶ame-value瀵圭殑鍒嗛殧鏍囪銆
{return} string 宸叉瀯閫犵殑URL
婧愮爜锛 framework/base/CApplication.php#535 (鏄剧ず)
public function createAbsoluteUrl($route,$params=array(),$schema='',$ampersand='&')
{
    
$url=$this->createUrl($route,$params,$ampersand);
    if(
strpos($url,'http')===0)
        return 
$url;
    else
        return 
$this->getRequest()->getHostInfo($schema).$url;
}

鍒涘缓涓涓熀浜庣粰瀹氭帶鍒跺櫒鍜屽姩浣滐紙淇℃伅锛夌粷瀵圭殑URL銆

createUrl() 鏂规硶
public string createUrl(string $route, array $params=array ( ), string $ampersand='&')
$route string URL璺敱銆傚畠鐨勬牸寮忓簲璇ユ槸锛氣楥ontrollerID/ActionID鈥欍
$params array 闄勫姞鐨凣ET鍙傛暟锛坣ame=>value锛夈傚悕绉板拰鍊间細琚玌RL-encoded锛圲RL缂栫爜锛夈
$ampersand string URL涓璶ame-value瀵圭殑鍒嗛殧鏍囪銆
{return} string 宸叉瀯閫犵殑URL
婧愮爜锛 framework/base/CApplication.php#522 (鏄剧ず)
public function createUrl($route,$params=array(),$ampersand='&')
{
    return 
$this->getUrlManager()->createUrl($route,$params,$ampersand);
}

鍒涘缓涓涓熀浜庣粰瀹氭帶鍒跺櫒鍜屽姩浣滐紙淇℃伅锛夌浉瀵圭殑URL銆

displayError() 鏂规硶
public void displayError(integer $code, string $message, string $file, string $line)
$code integer 閿欒浠g爜
$message string 閿欒淇℃伅
$file string error 閿欒鏂囦欢
$line string error 閿欒琛屽彿
婧愮爜锛 framework/base/CApplication.php#864 (鏄剧ず)
public function displayError($code,$message,$file,$line)
{
    if(
YII_DEBUG)
    {
        echo 
"<h1>PHP Error [$code]</h1>\n";
        echo 
"<p>$message ($file:$line)</p>\n";
        echo 
'<pre>';

        
$trace=debug_backtrace();
        
// skip the first 3 stacks as they do not tell the error position
        
if(count($trace)>3)
            
$trace=array_slice($trace,3);
        foreach(
$trace as $i=>$t)
        {
            if(!isset(
$t['file']))
                
$t['file']='unknown';
            if(!isset(
$t['line']))
                
$t['line']=0;
            if(!isset(
$t['function']))
                
$t['function']='unknown';
            echo 
"#$i {$t['file']}({$t['line']}): ";
            if(isset(
$t['object']) && is_object($t['object']))
                echo 
get_class($t['object']).'->';
            echo 
"{$t['function']}()\n";
        }

        echo 
'</pre>';
    }
    else
    {
        echo 
"<h1>PHP Error [$code]</h1>\n";
        echo 
"<p>$message</p>\n";
    }
}

鏄剧ず鎹曡幏鐨凱HP閿欒銆 褰撴病鏈夋縺娲婚敊璇鐞嗘椂锛 杩欎釜鏂瑰皢鍦℉TML鏄剧ず閿欒銆

displayException() 鏂规硶
public void displayException(Exception $exception)
$exception Exception 鏈崟鑾风殑寮傚父
婧愮爜锛 framework/base/CApplication.php#905 (鏄剧ず)
public function displayException($exception)
{
    if(
YII_DEBUG)
    {
        echo 
'<h1>'.get_class($exception)."</h1>\n";
        echo 
'<p>'.$exception->getMessage().' ('.$exception->getFile().':'.$exception->getLine().')</p>';
        echo 
'<pre>'.$exception->getTraceAsString().'</pre>';
    }
    else
    {
        echo 
'<h1>'.get_class($exception)."</h1>\n";
        echo 
'<p>'.$exception->getMessage().'</p>';
    }
}

鏄剧ず鏈崟鑾风殑PHP寮傚父銆 褰撴病鏈夋縺娲婚敊璇鐞嗘椂锛 杩欎釜鏂规硶灏嗗湪HTML鏄剧ず鏈崟鑾峰紓甯搞

end() 鏂规硶
public void end(integer $status=0, boolean $exit=true)
$status integer 閫鍑虹姸鎬侊紙0浠h〃姝e父閫鍑猴紝鍏跺畠鍊艰〃绀哄紓甯搁鍑猴級銆
$exit boolean 鏄惁瑕侀鍑哄綋鍓嶇殑璇锋眰銆傝繖涓弬鏁板彲鐢ㄨ嚜1.1.5銆 濡傛灉榛樿涓簍ure锛屾剰鍛崇潃灏嗗湪杩欎釜鏂规硶缁撴潫鏃惰皟鐢≒HP鐨別xit()鍑芥暟銆
婧愮爜锛 framework/base/CApplication.php#175 (鏄剧ず)
public function end($status=0$exit=true)
{
    if(
$this->hasEventHandler('onEndRequest'))
        
$this->onEndRequest(new CEvent($this));
    if(
$exit)
        exit(
$status);
}

缁堟搴旂敤绋嬪簭銆 杩欎釜鏂规硶閫氳繃鍦ㄩ鍑哄墠璋冪敤onEndRequest 鏇挎崲PHP鐨別xit()鏂规硶銆

findLocalizedFile() 鏂规硶
public string findLocalizedFile(string $srcFile, string $srcLanguage=NULL, string $language=NULL)
$srcFile string 鍘熸枃浠
$srcLanguage string 鍘熸枃浠朵腑鐨勮瑷锛屽鏋滀负null锛屽皢浣跨敤source language
$language string 鎵闇瑕佺殑鏈湴璇█.濡傛灉涓簄ull, 灏嗕娇鐢application language
{return} string 鍖归厤鐨勬湰鍦板寲鏂囦欢銆傚鏋滄病鏈夋湰鍦板寲鏂囦欢鎴栧鏋滄簮璇█鍜岃姹傝瑷鐩稿悓锛 灏嗚繑鍥炲師濮嬫枃浠躲
婧愮爜锛 framework/base/CApplication.php#364 (鏄剧ず)
public function findLocalizedFile($srcFile,$srcLanguage=null,$language=null)
{
    if(
$srcLanguage===null)
        
$srcLanguage=$this->sourceLanguage;
    if(
$language===null)
        
$language=$this->getLanguage();
    if(
$language===$srcLanguage)
        return 
$srcFile;
    
$desiredFile=dirname($srcFile).DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.basename($srcFile);
    return 
is_file($desiredFile) ? $desiredFile $srcFile;
}

杩斿洖鎸囧畾鏂囦欢鐨勬湰鍦板寲鐗堟湰銆

鍩轰簬鎸囧畾璇█浠g爜鎼滅储銆 鐗瑰埆鏄紝鍏锋湁鐩稿悓鍚嶇О鐨勬枃浠跺皢鍦ㄤ互鏈湴ID鍛藉悕瀛愮洰褰曚笅鏌ユ壘銆 渚嬪銆傜粰瀹氭枃浠垛減ath/to/view.php鈥濆拰鏈湴ID鏍囪瘑锛氣渮h_cn鈥濓紝 鏈湴鍖栨枃浠跺皢浠ヨ繖绉嶅舰寮忔煡鎵锯減ath/to/zh_cn/view.php鈥濄 濡傛灉璇ユ枃浠舵病鏈夋壘鍒帮紝 灏嗚繑鍥炲師濮嬫枃浠躲

涓轰簡淇濇寔涓鑷存э紝寤鸿鏈湴璇█id浣跨敤灏忓啓鏍煎紡 LanguageID_RegionID锛堜緥濡傦紝鈥渆n_us鈥濓級銆

getBasePath() 鏂规硶
public string getBasePath()
{return} string 搴旂敤绋嬪簭鐨勬牴鐩綍銆傞粯璁や负鈥榩rotected鈥欍
婧愮爜锛 framework/base/CApplication.php#230 (鏄剧ず)
public function getBasePath()
{
    return 
$this->_basePath;
}

杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆

getBaseUrl() 鏂规硶
public string getBaseUrl(boolean $absolute=false)
$absolute boolean 鏄惁杩斿洖涓涓粷瀵筓RL銆傞粯璁や负false锛屾剰鍛崇潃杩斿洖涓涓浉瀵圭殑URL銆
{return} string 鐩稿叧URL鐨勫簲鐢ㄣ
婧愮爜锛 framework/base/CApplication.php#551 (鏄剧ず)
public function getBaseUrl($absolute=false)
{
    return 
$this->getRequest()->getBaseUrl($absolute);
}

杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 蹇嵎鏂规硶灏辨槸CHttpRequest::getBaseUrl()

getCache() 鏂规硶
public CCache getCache()
{return} CCache 搴旂敤绋嬪簭缂撳瓨缁勪欢銆俷ull涓轰笉鍚敤杩欎釜缁勪欢銆
婧愮爜锛 framework/base/CApplication.php#465 (鏄剧ず)
public function getCache()
{
    return 
$this->getComponent('cache');
}

杩斿洖缂撳瓨缁勪欢銆

getController() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.8锛
public CController getController()
{return} CController 褰撳墠娲诲姩鎺у埗鍣ㄣ備负Null杩斿洖瀹冪殑鍩虹被銆
婧愮爜锛 framework/base/CApplication.php#510 (鏄剧ず)
public function getController()
{
    return 
null;
}

getCoreMessages() 鏂规硶
public CPhpMessageSource getCoreMessages()
{return} CPhpMessageSource 鏍稿績淇℃伅缈昏瘧
婧愮爜锛 framework/base/CApplication.php#474 (鏄剧ず)
public function getCoreMessages()
{
    return 
$this->getComponent('coreMessages');
}

杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆

getDateFormatter() 鏂规硶
public CDateFormatter getDateFormatter()
{return} CDateFormatter 鏈湴鍖栫殑鏃ユ湡鏍煎紡銆 灏嗕細浣跨敤褰撳墠application locale
婧愮爜锛 framework/base/CApplication.php#420 (鏄剧ず)
public function getDateFormatter()
{
    return 
$this->getLocale()->getDateFormatter();
}

杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆

getDb() 鏂规硶
public CDbConnection getDb()
{return} CDbConnection 鏁版嵁搴撹繛鎺
婧愮爜锛 framework/base/CApplication.php#429 (鏄剧ず)
public function getDb()
{
    return 
$this->getComponent('db');
}

杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲

getErrorHandler() 鏂规硶
public CErrorHandler getErrorHandler()
{return} CErrorHandler 閿欒澶勭悊搴旂敤绋嬪簭缁勪欢銆
婧愮爜锛 framework/base/CApplication.php#438 (鏄剧ず)
public function getErrorHandler()
{
    return 
$this->getComponent('errorHandler');
}

杩斿洖閿欒澶勭悊缁勪欢銆

getExtensionPath() 鏂规硶
public string getExtensionPath()
{return} string 鍖呭惈鎵鏈夋墿灞曠殑鐩綍銆傞粯璁ゆ槸鈥榩rotected鈥欎笅鐨勨榚xtensions鈥欑洰褰曘
婧愮爜锛 framework/base/CApplication.php#280 (鏄剧ず)
public function getExtensionPath()
{
    return 
Yii::getPathOfAlias('ext');
}

杩斿洖绗笁鏂规墿灞曟牴鐩綍銆

getGlobalState() 鏂规硶
public mixed getGlobalState(string $key, mixed $defaultValue=NULL)
$key string 瑕佽繑鍥炵殑鍊肩殑鍚嶇О
$defaultValue mixed 榛樿鍊笺傚鏋滆鍚嶇О鐨勫叏灞鍊兼病鏈夋壘鍒帮紝灏嗚繑鍥為粯璁ゅ笺
{return} mixed 鍏ㄥ眬鍊肩殑鍚嶇О
婧愮爜锛 framework/base/CApplication.php#589 (鏄剧ず)
public function getGlobalState($key,$defaultValue=null)
{
    if(
$this->_globalState===null)
        
$this->loadGlobalState();
    if(isset(
$this->_globalState[$key]))
        return 
$this->_globalState[$key];
    else
        return 
$defaultValue;
}

杩斿洖涓涓叏灞鍊

涓涓叏灞鍊硷紝鎸佺画鍦ㄦ槸鐢ㄦ埛鐨剆essions涓巖equests涔嬮棿銆

鍙傝

getHomeUrl() 鏂规硶
public string getHomeUrl()
{return} string 涓婚〉URL
婧愮爜锛 framework/base/CApplication.php#559 (鏄剧ず)
public function getHomeUrl()
{
    if(
$this->_homeUrl===null)
    {
        if(
$this->getUrlManager()->showScriptName)
            return 
$this->getRequest()->getScriptUrl();
        else
            return 
$this->getRequest()->getBaseUrl().'/';
    }
    else
        return 
$this->_homeUrl;
}

getId() 鏂规硶
public string getId()
{return} string $id 搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆
婧愮爜锛 framework/base/CApplication.php#209 (鏄剧ず)
public function getId()
{
    if(
$this->_id!==null)
        return 
$this->_id;
    else
        return 
$this->_id=sprintf('%x',crc32($this->getBasePath().$this->name));
}

杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺

getLanguage() 鏂规硶
public string getLanguage()
{return} string 鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆 榛樿涓source language
婧愮爜锛 framework/base/CApplication.php#302 (鏄剧ず)
public function getLanguage()
{
    return 
$this->_language===null $this->sourceLanguage $this->_language;
}

杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆

getLocale() 鏂规硶
public CLocale getLocale(string $localeID=NULL)
$localeID string 鏈湴锛堢幆澧冿級瀹炰緥ID锛堜緥濡傦紝en_US锛夈傚鏋渘ull锛屽皢浣跨敤application language ID
{return} CLocale 鏈湴锛堢幆澧冿級瀹炰緥
婧愮爜锛 framework/base/CApplication.php#381 (鏄剧ず)
public function getLocale($localeID=null)
{
    return 
CLocale::getInstance($localeID===null?$this->getLanguage():$localeID);
}

杩斿洖鏈湴锛堢幆澧冿級瀹炰緥銆

getLocaleDataPath() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.0锛
public string getLocaleDataPath()
{return} string 鍖呭惈鏈湴鐨勬暟鎹寲鐩綍銆傞粯璁や负鈥榝ramework/i18n/data鈥欍
婧愮爜锛 framework/base/CApplication.php#391 (鏄剧ず)
public function getLocaleDataPath()
{
    return 
CLocale::$dataPath===null Yii::getPathOfAlias('system.i18n.data') : CLocale::$dataPath;
}

杩斿洖鍖呭惈鏈湴鍖栫殑鏁版嵁鐩綍銆

getMessages() 鏂规硶
public CMessageSource getMessages()
{return} CMessageSource 搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢
婧愮爜锛 framework/base/CApplication.php#483 (鏄剧ず)
public function getMessages()
{
    return 
$this->getComponent('messages');
}

杩斿洖搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢銆

getNumberFormatter() 鏂规硶
public CNumberFormatter getNumberFormatter()
{return} CNumberFormatter 鏈湴鍖栨暟瀛楁牸寮忋 灏嗕娇鐢ㄥ綋鍓application locale
婧愮爜锛 framework/base/CApplication.php#410 (鏄剧ず)
public function getNumberFormatter()
{
    return 
$this->getLocale()->getNumberFormatter();
}

getRequest() 鏂规硶
public CHttpRequest getRequest()
{return} CHttpRequest 璇锋眰缁勪欢
婧愮爜锛 framework/base/CApplication.php#492 (鏄剧ず)
public function getRequest()
{
    return 
$this->getComponent('request');
}

杩斿洖璇锋眰缁勪欢銆

getRuntimePath() 鏂规硶
public string getRuntimePath()
{return} string 瀛樺偍杩愯鏃舵枃浠剁洰褰曘傞粯璁や负鈥榩rotected/runtime鈥欍
婧愮爜锛 framework/base/CApplication.php#252 (鏄剧ず)
public function getRuntimePath()
{
    if(
$this->_runtimePath!==null)
        return 
$this->_runtimePath;
    else
    {
        
$this->setRuntimePath($this->getBasePath().DIRECTORY_SEPARATOR.'runtime');
        return 
$this->_runtimePath;
    }
}

杩斿洖瀛樺偍杩愯鏃舵枃浠剁洰褰曘

getSecurityManager() 鏂规硶
public CSecurityManager getSecurityManager()
{return} CSecurityManager 瀹夊叏绠$悊鍣ㄧ粍浠躲
婧愮爜锛 framework/base/CApplication.php#447 (鏄剧ず)
public function getSecurityManager()
{
    return 
$this->getComponent('securityManager');
}

杩斿洖瀹夊叏绠$悊鍣ㄧ粍浠躲

getStatePersister() 鏂规硶
public CStatePersister getStatePersister()
{return} CStatePersister 鎸佷箙鐘舵佺粍浠躲
婧愮爜锛 framework/base/CApplication.php#456 (鏄剧ず)
public function getStatePersister()
{
    return 
$this->getComponent('statePersister');
}

杩斿洖鎸佷箙鐘舵佺粍浠躲

getTimeZone() 鏂规硶
public string getTimeZone()
{return} string 搴旂敤绋嬪簭浣跨敤鐨勬椂鍖恒
婧愮爜锛 framework/base/CApplication.php#329 (鏄剧ず)
public function getTimeZone()
{
    return 
date_default_timezone_get();
}

杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 杩欎釜涓涓畝鍗曠殑PHP鍑芥暟date_default_timezone_get()鐨勫皝瑁呫

getUrlManager() 鏂规硶
public CUrlManager getUrlManager()
{return} CUrlManager URL绠$悊鍣ㄧ粍浠
婧愮爜锛 framework/base/CApplication.php#501 (鏄剧ず)
public function getUrlManager()
{
    return 
$this->getComponent('urlManager');
}

杩斿洖URL绠$悊鍣ㄧ粍浠躲

handleError() 鏂规硶
public void handleError(integer $code, string $message, string $file, integer $line)
$code integer 鍙戣捣閿欒鐨勭瓑绾
$message string 鍙戣捣閿欒鐨勪俊鎭
$file string 鍙戣捣閿欒鐨勬枃浠
$line integer 鍙戣捣閿欒鐨勮鍙
婧愮爜锛 framework/base/CApplication.php#758 (鏄剧ず)
public function handleError($code,$message,$file,$line)
{
    if(
$code error_reporting())
    {
        
// disable error capturing to avoid recursive errors
        
restore_error_handler();
        
restore_exception_handler();

        
$log="$message ($file:$line)\nStack trace:\n";
        
$trace=debug_backtrace();
        
// skip the first 3 stacks as they do not tell the error position
        
if(count($trace)>3)
            
$trace=array_slice($trace,3);
        foreach(
$trace as $i=>$t)
        {
            if(!isset(
$t['file']))
                
$t['file']='unknown';
            if(!isset(
$t['line']))
                
$t['line']=0;
            if(!isset(
$t['function']))
                
$t['function']='unknown';
            
$log.="#$i {$t['file']}({$t['line']}): ";
            if(isset(
$t['object']) && is_object($t['object']))
                
$log.=get_class($t['object']).'->';
            
$log.="{$t['function']}()\n";
        }
        if(isset(
$_SERVER['REQUEST_URI']))
            
$log.='REQUEST_URI='.$_SERVER['REQUEST_URI'];
        
Yii::log($log,CLogger::LEVEL_ERROR,'php');

        try
        {
            
Yii::import('CErrorEvent',true);
            
$event=new CErrorEvent($this,$code,$message,$file,$line);
            
$this->onError($event);
            if(!
$event->handled)
            {
                
// try an error handler
                
if(($handler=$this->getErrorHandler())!==null)
                    
$handler->handle($event);
                else
                    
$this->displayError($code,$message,$file,$line);
            }
        }
        catch(
Exception $e)
        {
            
$this->displayException($e);
        }

        try
        {
            
$this->end(1);
        }
        catch(
Exception $e)
        {
            
// use the most primitive way to log error
            
$msg get_class($e).': '.$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
            
$msg .= $e->getTraceAsString()."\n";
            
$msg .= "Previous error:\n";
            
$msg .= $log."\n";
            
$msg .= '$_SERVER='.var_export($_SERVER,true);
            
error_log($msg);
            exit(
1);
        }
    }
}

澶勭悊PHP寮傚父閿欒锛屽璀﹀憡锛岄氱煡銆

杩欎釜鏂规硶瀹炵幇浜嗕竴涓狿HP鐨勯敊璇鐞嗐 瀹冮渶瑕佸父閲廦II_ENABLE_ERROR_HANDLER琚畾涔変负true銆

杩欎釜鏂规硶灏嗛鍏堝彂璧蜂竴涓onError浜嬩欢銆 濡傛灉璇ラ敊璇病鏈夎浠讳綍浜嬩欢澶勭悊绋嬪簭澶勭悊锛屽畠灏嗚皟鐢 errorHandler澶勭悊閿欒銆

搴旂敤绋嬪簭灏嗚姝ゆ柟娉曠粓姝€

handleException() 鏂规硶
public void handleException(Exception $exception)
$exception Exception 寮傚父娌℃湁琚崟鑾
婧愮爜锛 framework/base/CApplication.php#687 (鏄剧ず)
public function handleException($exception)
{
    
// disable error capturing to avoid recursive errors
    
restore_error_handler();
    
restore_exception_handler();

    
$category='exception.'.get_class($exception);
    if(
$exception instanceof CHttpException)
        
$category.='.'.$exception->statusCode;
    
// php <5.2 doesn't support string conversion auto-magically
    
$message=$exception->__toString();
    if(isset(
$_SERVER['REQUEST_URI']))
        
$message.="\nREQUEST_URI=".$_SERVER['REQUEST_URI'];
    if(isset(
$_SERVER['HTTP_REFERER']))
        
$message.="\nHTTP_REFERER=".$_SERVER['HTTP_REFERER'];
    
$message.="\n---";
    
Yii::log($message,CLogger::LEVEL_ERROR,$category);

    try
    {
        
$event=new CExceptionEvent($this,$exception);
        
$this->onException($event);
        if(!
$event->handled)
        {
            
// try an error handler
            
if(($handler=$this->getErrorHandler())!==null)
                
$handler->handle($event);
            else
                
$this->displayException($exception);
        }
    }
    catch(
Exception $e)
    {
        
$this->displayException($e);
    }

    try
    {
        
$this->end(1);
    }
    catch(
Exception $e)
    {
        
// use the most primitive way to log error
        
$msg get_class($e).': '.$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
        
$msg .= $e->getTraceAsString()."\n";
        
$msg .= "Previous exception:\n";
        
$msg .= get_class($exception).': '.$exception->getMessage().' ('.$exception->getFile().':'.$exception->getLine().")\n";
        
$msg .= $exception->getTraceAsString()."\n";
        
$msg .= '$_SERVER='.var_export($_SERVER,true);
        
error_log($msg);
        exit(
1);
    }
}

澶勭悊鏈崟鑾风殑PHP寮傚父銆

杩欎釜鏂规硶瀹炵幇浜嗕竴涓狿HP鐨勫紓甯稿鐞嗐 瀹冮渶瑕佸畠闇瑕佸父閲廦II_ENABLE_EXCEPTION_HANDLER琚畾涔変负true.

杩欎釜鏂规硶灏嗛鍏堝彂璧蜂竴涓onException浜嬩欢銆 濡傛灉寮傚父娌℃湁琚换浣曚簨浠跺鐞嗙▼搴忓鐞嗭紝瀹冨皢璋冪敤 errorHandler澶勭悊寮傚父銆

搴旂敤绋嬪簭灏嗚姝ゆ柟娉曠粓姝€

initSystemHandlers() 鏂规硶
protected void initSystemHandlers()
婧愮爜锛 framework/base/CApplication.php#923 (鏄剧ず)
protected function initSystemHandlers()
{
    if(
YII_ENABLE_EXCEPTION_HANDLER)
        
set_exception_handler(array($this,'handleException'));
    if(
YII_ENABLE_ERROR_HANDLER)
        
set_error_handler(array($this,'handleError'),error_reporting());
}

鍒濆鍖栫被鑷姩鍔犺浇鍣ㄥ拰閿欒澶勭悊銆

loadGlobalState() 鏂规硶
public void loadGlobalState()
婧愮爜锛 framework/base/CApplication.php#649 (鏄剧ず)
public function loadGlobalState()
{
    
$persister=$this->getStatePersister();
    if((
$this->_globalState=$persister->load())===null)
        
$this->_globalState=array();
    
$this->_stateChanged=false;
    
$this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
}

浠庢寔涔呭瓨鍌ㄥ姞杞藉叏灞鐘舵佹暟鎹

鍙傝

onBeginRequest() 鏂规硶
public void onBeginRequest(CEvent $event)
$event CEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/base/CApplication.php#187 (鏄剧ず)
public function onBeginRequest($event)
{
    
$this->raiseEvent('onBeginRequest',$event);
}

搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪墠鍙戣捣銆

onEndRequest() 鏂规硶
public void onEndRequest(CEvent $event)
$event CEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/base/CApplication.php#196 (鏄剧ず)
public function onEndRequest($event)
{
    if(!
$this->_ended)
    {
        
$this->_ended=true;
        
$this->raiseEvent('onEndRequest',$event);
    }
}

搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪悗鍙戣捣銆

onError() 鏂规硶
public void onError(CErrorEvent $event)
$event CErrorEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/base/CApplication.php#850 (鏄剧ず)
public function onError($event)
{
    
$this->raiseEvent('onError',$event);
}

褰撲竴涓狿HP寮傚父閿欒鍙戠敓鏃跺彂璧枫

鍙互璁剧疆涓涓簨浠跺鐞handled锛 浜嬩欢鍙傛暟鐨勫睘鎬т负true琛ㄧず涓嶅啀闇瑕佽繘涓姝ュ鐞嗛敊璇 鍚﹀垯锛errorHandler 搴旂敤缁勪欢灏嗙户缁鐞嗛敊璇

onException() 鏂规硶
public void onException(CExceptionEvent $event)
$event CExceptionEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/base/CApplication.php#835 (鏄剧ず)
public function onException($event)
{
    
$this->raiseEvent('onException',$event);
}

褰撲竴涓湭鎹曡幏鐨凱HP寮傚父鍙戠敓鏃跺彂璧枫

鍙互璁剧疆涓涓簨浠跺鐞handled锛 浜嬩欢鍙傛暟鐨勫睘鎬т负true琛ㄧず涓嶅啀闇瑕佽繘涓姝ュ鐞嗛敊璇 鍚﹀垯锛errorHandler 搴旂敤缁勪欢灏嗙户缁鐞嗛敊璇

processRequest() 鏂规硶
abstract public void processRequest()
婧愮爜锛 framework/base/CApplication.php#110 (鏄剧ず)
abstract public function processRequest();

澶勭悊璇锋眰銆 杩欏疄闄呮槸璇峰鐞嗗伐浣滃凡缁忓畬鎴愮殑鍦版柟銆 娲剧敓绫诲簲璇ラ噸鍐欐鏂规硶銆

registerCoreComponents() 鏂规硶
protected void registerCoreComponents()
婧愮爜锛 framework/base/CApplication.php#935 (鏄剧ず)
protected function registerCoreComponents()
{
    
$components=array(
        
'coreMessages'=>array(
            
'class'=>'CPhpMessageSource',
            
'language'=>'en_us',
            
'basePath'=>YII_PATH.DIRECTORY_SEPARATOR.'messages',
        ),
        
'db'=>array(
            
'class'=>'CDbConnection',
        ),
        
'messages'=>array(
            
'class'=>'CPhpMessageSource',
        ),
        
'errorHandler'=>array(
            
'class'=>'CErrorHandler',
        ),
        
'securityManager'=>array(
            
'class'=>'CSecurityManager',
        ),
        
'statePersister'=>array(
            
'class'=>'CStatePersister',
        ),
        
'urlManager'=>array(
            
'class'=>'CUrlManager',
        ),
        
'request'=>array(
            
'class'=>'CHttpRequest',
        ),
        
'format'=>array(
            
'class'=>'CFormatter',
        ),
    );

    
$this->setComponents($components);
}

娉ㄥ唽鏍稿績搴旂敤缁勪欢銆

鍙傝

run() 鏂规硶
public void run()
婧愮爜锛 framework/base/CApplication.php#158 (鏄剧ず)
public function run()
{
    if(
$this->hasEventHandler('onBeginRequest'))
        
$this->onBeginRequest(new CEvent($this));
    
$this->processRequest();
    if(
$this->hasEventHandler('onEndRequest'))
        
$this->onEndRequest(new CEvent($this));
}

杩愯搴旂敤绋嬪簭銆 姝ゆ柟娉曞姞杞介潤鎬佸簲鐢ㄧ粍浠躲 娲剧敓绫婚氬父閲嶅啓姝ゆ柟娉曞幓鍋氭洿澶氱壒瀹氬簲鐢ㄣ 璁颁綇瑕佽皟鐢ㄧ埗绫诲疄鐜帮紝浠ヤ娇闈欐佸簲鐢ㄧ粍浠惰鍔犺浇銆

saveGlobalState() 鏂规硶
public void saveGlobalState()
婧愮爜锛 framework/base/CApplication.php#663 (鏄剧ず)
public function saveGlobalState()
{
    if(
$this->_stateChanged)
    {
        
$this->_stateChanged=false;
        
$this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
        
$this->getStatePersister()->save($this->_globalState);
    }
}

淇濆瓨鍏ㄥ眬鐘舵佹暟鎹埌鎸佷箙瀛樺偍銆

鍙傝

setBasePath() 鏂规硶
public void setBasePath(string $path)
$path string 搴旂敤绋嬪簭鏍圭洰褰曘
婧愮爜锛 framework/base/CApplication.php#241 (鏄剧ず)
public function setBasePath($path)
{
    if((
$this->_basePath=realpath($path))===false || !is_dir($this->_basePath))
        throw new 
CException(Yii::t('yii','Application base path "{path}" is not a valid directory.',
            array(
'{path}'=>$path)));
}

璁剧疆搴旂敤绋嬪簭鏍圭洰褰曘 杩欎釜鏂规硶浠呭湪鏋勯犲嚱鏁版椂璋冪敤銆

setExtensionPath() 鏂规硶
public void setExtensionPath(string $path)
$path string 绗笁鏂规墿灞曠洰褰曘
婧愮爜锛 framework/base/CApplication.php#289 (鏄剧ず)
public function setExtensionPath($path)
{
    if((
$extensionPath=realpath($path))===false || !is_dir($extensionPath))
        throw new 
CException(Yii::t('yii','Extension path "{path}" does not exist.',
            array(
'{path}'=>$path)));
    
Yii::setPathOfAlias('ext',$extensionPath);
}

璁剧疆绗笁鏂规墿灞曠洰褰曘

setGlobalState() 鏂规硶
public void setGlobalState(string $key, mixed $value, mixed $defaultValue=NULL)
$key string 瑕佷繚瀛樼殑鍊肩殑鍚嶇О
$value mixed 琚繚瀛樼殑鍏ㄥ眬鍊硷紝瀹冨繀椤绘槸搴忎緥鍖栫殑銆
$defaultValue mixed 榛樿鍊笺傚鏋滆繖涓间笌鍏ㄥ眬鍊间笂鍚岋紝瀹冨皢娓呴櫎褰撳墠瀛樺偍銆
婧愮爜锛 framework/base/CApplication.php#609 (鏄剧ず)
public function setGlobalState($key,$value,$defaultValue=null)
{
    if(
$this->_globalState===null)
        
$this->loadGlobalState();

    
$changed=$this->_stateChanged;
    if(
$value===$defaultValue)
    {
        if(isset(
$this->_globalState[$key]))
        {
            unset(
$this->_globalState[$key]);
            
$this->_stateChanged=true;
        }
    }
    else if(!isset(
$this->_globalState[$key]) || $this->_globalState[$key]!==$value)
    {
        
$this->_globalState[$key]=$value;
        
$this->_stateChanged=true;
    }

    if(
$this->_stateChanged!==$changed)
        
$this->attachEventHandler('onEndRequest',array($this,'saveGlobalState'));
}

璁剧疆涓涓叏灞鍊笺

涓涓叏灞鍊硷紝鎸佺画鍦ㄦ槸鐢ㄦ埛鐨剆essions涓巖equests涔嬮棿銆 纭繚杩欎釜鍊煎彲浠ュ簭渚嬪寲鍜屽弽搴忎緥鍖栥

鍙傝

setHomeUrl() 鏂规硶
public void setHomeUrl(string $value)
$value string 璁剧疆涓婚〉URL
婧愮爜锛 framework/base/CApplication.php#575 (鏄剧ず)
public function setHomeUrl($value)
{
    
$this->_homeUrl=$value;
}

setId() 鏂规硶
public void setId(string $id)
$id string 搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆
婧愮爜锛 framework/base/CApplication.php#221 (鏄剧ず)
public function setId($id)
{
    
$this->_id=$id;
}

璁剧疆搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆

setLanguage() 鏂规硶
public void setLanguage(string $language)
$language string 鐢ㄦ埛鐨勮瑷锛堜緥濡傦紝鈥榚n_US鈥欙紝鈥榸h_CN鈥欙級銆 濡傛灉涓簄ull锛屽皢浣跨敤sourceLanguage
婧愮爜锛 framework/base/CApplication.php#318 (鏄剧ず)
public function setLanguage($language)
{
    
$this->_language=$language;
}

鎸囧畾搴旂敤绋嬪簭璇█銆

杩欎釜鏄簲鐢ㄧ▼搴忔樉绀烘渶缁堢敤鎴风殑璇█銆 濡傛灉涓簄ull锛屽畠灏嗕娇鐢source language

闄ら潪浣犵殑搴旂敤绋嬪簭闇瑕佹敮鎸佸璇█锛 鍚﹀垯浣犲簲璇ユ绘槸璁剧疆language涓簄ull锛屼互鏈澶у寲搴旂敤绋嬪簭鐨勬ц兘銆

setLocaleDataPath() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.0锛
public void setLocaleDataPath(string $value)
$value string 鍖呭惈鏈湴鍖栨暟鎹殑鐩綍銆
婧愮爜锛 framework/base/CApplication.php#401 (鏄剧ず)
public function setLocaleDataPath($value)
{
    
CLocale::$dataPath=$value;
}

璁剧疆鍖呭惈鏈湴鍖栨暟鎹殑鐩綍銆

setRuntimePath() 鏂规硶
public void setRuntimePath(string $path)
$path string 瀛樺偍杩愯鏃舵枃浠剁洰褰曘
婧愮爜锛 framework/base/CApplication.php#268 (鏄剧ず)
public function setRuntimePath($path)
{
    if((
$runtimePath=realpath($path))===false || !is_dir($runtimePath) || !is_writable($runtimePath))
        throw new 
CException(Yii::t('yii','Application runtime path "{path}" is not valid. Please make sure it is a directory writable by the Web server process.',
            array(
'{path}'=>$path)));
    
$this->_runtimePath=$runtimePath;
}

璁剧疆瀛樺偍杩愯鏃舵枃浠剁洰褰曘

setTimeZone() 鏂规硶
public void setTimeZone(string $value)
$value string 搴旂敤绋嬪簭浣跨敤鐨勬椂鍖恒
婧愮爜锛 framework/base/CApplication.php#340 (鏄剧ず)
public function setTimeZone($value)
{
    
date_default_timezone_set($value);
}

璁剧疆搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 杩欎釜涓涓畝鍗曠殑PHP鍑芥暟date_default_timezone_set()鐨勫皝瑁呫

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