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 |
涓涓簲鐢ㄧ▼搴忔湇鍔″湪鐢ㄦ埛璇锋眰澶勭悊鐨勫叏灞鑼冨洿鍐呫 瀹冭礋璐d负鏁翠釜搴旂敤绋嬪簭绠$悊 鎻愪緵鍏蜂綋鍔熻兘鐨勫簲鐢ㄧ▼搴忕粍浠躲
CApplication鎵鎻愪緵鐨勬牳蹇冨簲鐢ㄧ粍浠跺涓嬶細
- errorHandler: 澶勭悊PHP閿欒鍜岄敊璇紓甯搞 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
- securityManager: 鎻愪緵瀹夊叏鐩稿叧鐨勬湇鍔★紝 渚嬪锛屽搱甯岋紝鍔犲瘑鍔熻兘銆 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
- statePersister: 鎻愪緵鍏ㄥ眬鐨勬寔涔呯姸鎬佹柟娉曘 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
- cache: 鎻愪緵缂撳瓨鍔熻兘銆 杩欎釜搴旂敤缁勪欢榛樿鏄姝㈢殑銆
- messages: 涓虹炕璇戝簲鐢ㄧ▼搴忎俊鎭彁渚涗俊鎭簮銆 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
- coreMessages: 涓虹炕璇慪ii妗嗘灦淇℃伅鎻愪緵淇℃伅婧愶紝 杩欎釜搴旂敤缁勪欢鍦ㄩ渶瑕佹椂鍔ㄦ佸姞杞姐
褰撳鐞嗙敤鎴疯姹傛椂锛孋Application灏嗙粡鍘嗗涓嬬殑鐢熷懡鍛ㄦ湡锛
- 鍔犺浇搴旂敤绋嬪簭閰嶇疆锛
- 璁剧疆绫昏嚜鍔ㄥ姞杞藉櫒鍜岄敊璇鐞嗭紱
- 鍔犺浇闈欐佸簲鐢ㄧ粍浠讹紱
- onBeginRequest: 澶勭悊鐢ㄦ埛璇锋眰鍓嶏紱
- processRequest: 澶勭悊鐢ㄦ埛璇锋眰鍓嶏紱
- 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 |
灞炴ц缁
杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆
杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 蹇嵎鏂规硶灏辨槸CHttpRequest::getBaseUrl()銆
杩斿洖缂撳瓨缁勪欢銆
搴旂敤绋嬪簭褰撳墠浣跨敤鐨勫瓧绗﹂泦銆傞粯璁や负鈥楿TF-8鈥欍
褰撳墠娲诲姩鎺у埗鍣ㄣ備负Null杩斿洖瀹冪殑鍩虹被銆
杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆
杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆
杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲
杩斿洖閿欒澶勭悊缁勪欢銆
杩斿洖绗笁鏂规墿灞曟牴鐩綍銆
涓婚〉URL
杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺
杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆
杩斿洖鏈湴锛堢幆澧冿級瀹炰緥銆
杩斿洖鍖呭惈鏈湴鍖栫殑鏁版嵁鐩綍銆
杩斿洖搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢銆
搴旂敤绋嬪簭鍚嶅瓧銆傞粯璁や负鈥楳y Application鈥欍
鏈湴鍖栨暟瀛楁牸寮忋 灏嗕娇鐢ㄥ綋鍓application locale銆
杩斿洖璇锋眰缁勪欢銆
杩斿洖瀛樺偍杩愯鏃舵枃浠剁洰褰曘
杩斿洖瀹夊叏绠$悊鍣ㄧ粍浠躲
搴旂敤绋嬪簭浣跨敤璇█. 杩欎釜璇█涓昏鎸囦俊鎭拰瑙嗗浘鏂囦欢涓殑璇█銆 榛樿鏄榚n_us鈥欙紙US English锛夈
杩斿洖鎸佷箙鐘舵佺粍浠躲
杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 杩欎釜涓涓畝鍗曠殑PHP鍑芥暟date_default_timezone_get()鐨勫皝瑁呫
杩斿洖URL绠$悊鍣ㄧ粍浠躲
鏂规硶璇︾粏
|
public void __construct(mixed $config=NULL)
| ||
| $config | mixed | 搴旂敤绋嬪簭閰嶇疆銆 濡傛灉鏄竴涓瓧绗︿覆锛屽畠灏嗚褰撲綔鍖呭惈閰嶇疆鐨勬枃浠惰矾寰勶紱 濡傛灉鏄竴涓暟缁勶紝瀹冨皢琚綋浣滃叿浣撶殑閰嶇疆淇℃伅锛 浣犵‘淇濆湪閰嶇疆鏂囦欢涓寚瀹basePath灞炴э紝 瀹冮氬父搴旇鎸囧悜鍚墍鏈夌殑搴旂敤绋嬪簭閫昏緫銆佹ā鏉垮拰鏁版嵁鐨勭洰褰曞寘銆 濡傛灉娌℃湁锛岄偅涔堥粯璁ゅ皢鎸囧畾涓衡榩rotected鈥欑洰褰曘 |
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();
}
鏋勯犲櫒銆
|
public void clearGlobalState(string $key)
| ||
| $key | string | 瑕佹竻闄ょ殑鍊肩殑鍚嶇О |
public function clearGlobalState($key)
{
$this->setGlobalState($key,true,true);
}
娓呯┖涓涓叏灞鍊笺
琚竻闄ょ殑鍊煎湪杩欐璇锋眰鎴栭殢鍚庣殑璇锋眰涓笉鍙娇鐢ㄣ
|
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 |
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銆
|
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 |
public function createUrl($route,$params=array(),$ampersand='&')
{
return $this->getUrlManager()->createUrl($route,$params,$ampersand);
}
鍒涘缓涓涓熀浜庣粰瀹氭帶鍒跺櫒鍜屽姩浣滐紙淇℃伅锛夌浉瀵圭殑URL銆
|
public void displayError(integer $code, string $message, string $file, string $line)
| ||
| $code | integer | 閿欒浠g爜 |
| $message | string | 閿欒淇℃伅 |
| $file | string | error 閿欒鏂囦欢 |
| $line | string | error 閿欒琛屽彿 |
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鏄剧ず閿欒銆
|
public void displayException(Exception $exception)
| ||
| $exception | Exception | 鏈崟鑾风殑寮傚父 |
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鏄剧ず鏈崟鑾峰紓甯搞
|
public void end(integer $status=0, boolean $exit=true)
| ||
| $status | integer | 閫鍑虹姸鎬侊紙0浠h〃姝e父閫鍑猴紝鍏跺畠鍊艰〃绀哄紓甯搁鍑猴級銆 |
| $exit | boolean | 鏄惁瑕侀鍑哄綋鍓嶇殑璇锋眰銆傝繖涓弬鏁板彲鐢ㄨ嚜1.1.5銆 濡傛灉榛樿涓簍ure锛屾剰鍛崇潃灏嗗湪杩欎釜鏂规硶缁撴潫鏃惰皟鐢≒HP鐨別xit()鍑芥暟銆 |
public function end($status=0, $exit=true)
{
if($this->hasEventHandler('onEndRequest'))
$this->onEndRequest(new CEvent($this));
if($exit)
exit($status);
}
缁堟搴旂敤绋嬪簭銆 杩欎釜鏂规硶閫氳繃鍦ㄩ鍑哄墠璋冪敤onEndRequest 鏇挎崲PHP鐨別xit()鏂规硶銆
|
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 | 鍖归厤鐨勬湰鍦板寲鏂囦欢銆傚鏋滄病鏈夋湰鍦板寲鏂囦欢鎴栧鏋滄簮璇█鍜岃姹傝瑷鐩稿悓锛 灏嗚繑鍥炲師濮嬫枃浠躲 |
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鈥濓級銆
|
public string getBasePath()
| ||
| {return} | string | 搴旂敤绋嬪簭鐨勬牴鐩綍銆傞粯璁や负鈥榩rotected鈥欍 |
public function getBasePath()
{
return $this->_basePath;
}
杩斿洖搴旂敤绋嬪簭鐨勬牴鐩綍銆
|
public string getBaseUrl(boolean $absolute=false)
| ||
| $absolute | boolean | 鏄惁杩斿洖涓涓粷瀵筓RL銆傞粯璁や负false锛屾剰鍛崇潃杩斿洖涓涓浉瀵圭殑URL銆 |
| {return} | string | 鐩稿叧URL鐨勫簲鐢ㄣ |
public function getBaseUrl($absolute=false)
{
return $this->getRequest()->getBaseUrl($absolute);
}
杩斿洖搴旂敤绋嬪簭鐨勭浉瀵筓RL銆 蹇嵎鏂规硶灏辨槸CHttpRequest::getBaseUrl()銆
|
public CCache getCache()
| ||
| {return} | CCache | 搴旂敤绋嬪簭缂撳瓨缁勪欢銆俷ull涓轰笉鍚敤杩欎釜缁勪欢銆 |
public function getCache()
{
return $this->getComponent('cache');
}
杩斿洖缂撳瓨缁勪欢銆
|
public CController getController()
| ||
| {return} | CController | 褰撳墠娲诲姩鎺у埗鍣ㄣ備负Null杩斿洖瀹冪殑鍩虹被銆 |
|
public CPhpMessageSource getCoreMessages()
| ||
| {return} | CPhpMessageSource | 鏍稿績淇℃伅缈昏瘧 |
public function getCoreMessages()
{
return $this->getComponent('coreMessages');
}
杩斿洖鏍稿績淇℃伅缈昏瘧缁勪欢銆
|
public CDateFormatter getDateFormatter()
| ||
| {return} | CDateFormatter | 鏈湴鍖栫殑鏃ユ湡鏍煎紡銆 灏嗕細浣跨敤褰撳墠application locale銆 |
public function getDateFormatter()
{
return $this->getLocale()->getDateFormatter();
}
杩斿洖鏈湴鍖栫殑鏃ユ湡鏍煎紡銆
|
public CDbConnection getDb()
| ||
| {return} | CDbConnection | 鏁版嵁搴撹繛鎺 |
public function getDb()
{
return $this->getComponent('db');
}
杩斿洖鏁版嵁搴撹繛鎺ョ粍浠躲
|
public CErrorHandler getErrorHandler()
| ||
| {return} | CErrorHandler | 閿欒澶勭悊搴旂敤绋嬪簭缁勪欢銆 |
public function getErrorHandler()
{
return $this->getComponent('errorHandler');
}
杩斿洖閿欒澶勭悊缁勪欢銆
|
public string getExtensionPath()
| ||
| {return} | string | 鍖呭惈鎵鏈夋墿灞曠殑鐩綍銆傞粯璁ゆ槸鈥榩rotected鈥欎笅鐨勨榚xtensions鈥欑洰褰曘 |
public function getExtensionPath()
{
return Yii::getPathOfAlias('ext');
}
杩斿洖绗笁鏂规墿灞曟牴鐩綍銆
|
public mixed getGlobalState(string $key, mixed $defaultValue=NULL)
| ||
| $key | string | 瑕佽繑鍥炵殑鍊肩殑鍚嶇О |
| $defaultValue | mixed | 榛樿鍊笺傚鏋滆鍚嶇О鐨勫叏灞鍊兼病鏈夋壘鍒帮紝灏嗚繑鍥為粯璁ゅ笺 |
| {return} | mixed | 鍏ㄥ眬鍊肩殑鍚嶇О |
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涔嬮棿銆
鍙傝
|
public string getHomeUrl()
| ||
| {return} | string | 涓婚〉URL |
public function getHomeUrl()
{
if($this->_homeUrl===null)
{
if($this->getUrlManager()->showScriptName)
return $this->getRequest()->getScriptUrl();
else
return $this->getRequest()->getBaseUrl().'/';
}
else
return $this->_homeUrl;
}
|
public string getId()
| ||
| {return} | string | $id 搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆 |
public function getId()
{
if($this->_id!==null)
return $this->_id;
else
return $this->_id=sprintf('%x',crc32($this->getBasePath().$this->name));
}
杩斿洖搴旂敤绋嬪簭鐨勫敮涓鏍囪瘑绗︺
|
public string getLanguage()
| ||
| {return} | string | 鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆 榛樿涓source language銆 |
public function getLanguage()
{
return $this->_language===null ? $this->sourceLanguage : $this->_language;
}
杩斿洖鐢ㄦ埛姝e湪浣跨敤鐨勫簲鐢ㄧ▼搴忚瑷銆
|
public CLocale getLocale(string $localeID=NULL)
| ||
| $localeID | string | 鏈湴锛堢幆澧冿級瀹炰緥ID锛堜緥濡傦紝en_US锛夈傚鏋渘ull锛屽皢浣跨敤application language ID銆 |
| {return} | CLocale | 鏈湴锛堢幆澧冿級瀹炰緥 |
public function getLocale($localeID=null)
{
return CLocale::getInstance($localeID===null?$this->getLanguage():$localeID);
}
杩斿洖鏈湴锛堢幆澧冿級瀹炰緥銆
|
public string getLocaleDataPath()
| ||
| {return} | string | 鍖呭惈鏈湴鐨勬暟鎹寲鐩綍銆傞粯璁や负鈥榝ramework/i18n/data鈥欍 |
public function getLocaleDataPath()
{
return CLocale::$dataPath===null ? Yii::getPathOfAlias('system.i18n.data') : CLocale::$dataPath;
}
杩斿洖鍖呭惈鏈湴鍖栫殑鏁版嵁鐩綍銆
|
public CMessageSource getMessages()
| ||
| {return} | CMessageSource | 搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢 |
public function getMessages()
{
return $this->getComponent('messages');
}
杩斿洖搴旂敤绋嬪簭淇℃伅缈昏瘧缁勪欢銆
|
public CNumberFormatter getNumberFormatter()
| ||
| {return} | CNumberFormatter | 鏈湴鍖栨暟瀛楁牸寮忋 灏嗕娇鐢ㄥ綋鍓application locale銆 |
public function getNumberFormatter()
{
return $this->getLocale()->getNumberFormatter();
}
|
public CHttpRequest getRequest()
| ||
| {return} | CHttpRequest | 璇锋眰缁勪欢 |
public function getRequest()
{
return $this->getComponent('request');
}
杩斿洖璇锋眰缁勪欢銆
|
public string getRuntimePath()
| ||
| {return} | string | 瀛樺偍杩愯鏃舵枃浠剁洰褰曘傞粯璁や负鈥榩rotected/runtime鈥欍 |
public function getRuntimePath()
{
if($this->_runtimePath!==null)
return $this->_runtimePath;
else
{
$this->setRuntimePath($this->getBasePath().DIRECTORY_SEPARATOR.'runtime');
return $this->_runtimePath;
}
}
杩斿洖瀛樺偍杩愯鏃舵枃浠剁洰褰曘
|
public CSecurityManager getSecurityManager()
| ||
| {return} | CSecurityManager | 瀹夊叏绠$悊鍣ㄧ粍浠躲 |
public function getSecurityManager()
{
return $this->getComponent('securityManager');
}
杩斿洖瀹夊叏绠$悊鍣ㄧ粍浠躲
|
public CStatePersister getStatePersister()
| ||
| {return} | CStatePersister | 鎸佷箙鐘舵佺粍浠躲 |
public function getStatePersister()
{
return $this->getComponent('statePersister');
}
杩斿洖鎸佷箙鐘舵佺粍浠躲
|
public string getTimeZone()
| ||
| {return} | string | 搴旂敤绋嬪簭浣跨敤鐨勬椂鍖恒 |
public function getTimeZone()
{
return date_default_timezone_get();
}
杩斿洖搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 杩欎釜涓涓畝鍗曠殑PHP鍑芥暟date_default_timezone_get()鐨勫皝瑁呫
|
public CUrlManager getUrlManager()
| ||
| {return} | CUrlManager | URL绠$悊鍣ㄧ粍浠 |
public function getUrlManager()
{
return $this->getComponent('urlManager');
}
杩斿洖URL绠$悊鍣ㄧ粍浠躲
|
public void handleError(integer $code, string $message, string $file, integer $line)
| ||
| $code | integer | 鍙戣捣閿欒鐨勭瓑绾 |
| $message | string | 鍙戣捣閿欒鐨勪俊鎭 |
| $file | string | 鍙戣捣閿欒鐨勬枃浠 |
| $line | integer | 鍙戣捣閿欒鐨勮鍙 |
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澶勭悊閿欒銆
搴旂敤绋嬪簭灏嗚姝ゆ柟娉曠粓姝€
|
public void handleException(Exception $exception)
| ||
| $exception | Exception | 寮傚父娌℃湁琚崟鑾 |
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澶勭悊寮傚父銆
搴旂敤绋嬪簭灏嗚姝ゆ柟娉曠粓姝€
|
protected void initSystemHandlers()
|
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());
}
鍒濆鍖栫被鑷姩鍔犺浇鍣ㄥ拰閿欒澶勭悊銆
|
public void loadGlobalState()
|
public function loadGlobalState()
{
$persister=$this->getStatePersister();
if(($this->_globalState=$persister->load())===null)
$this->_globalState=array();
$this->_stateChanged=false;
$this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
}
浠庢寔涔呭瓨鍌ㄥ姞杞藉叏灞鐘舵佹暟鎹
|
public void onBeginRequest(CEvent $event)
| ||
| $event | CEvent | 浜嬩欢鍙傛暟 |
public function onBeginRequest($event)
{
$this->raiseEvent('onBeginRequest',$event);
}
搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪墠鍙戣捣銆
|
public void onEndRequest(CEvent $event)
| ||
| $event | CEvent | 浜嬩欢鍙傛暟 |
public function onEndRequest($event)
{
if(!$this->_ended)
{
$this->_ended=true;
$this->raiseEvent('onEndRequest',$event);
}
}
搴旂敤绋嬪簭澶勭悊璇锋眰涔嬪悗鍙戣捣銆
|
public void onError(CErrorEvent $event)
| ||
| $event | CErrorEvent | 浜嬩欢鍙傛暟 |
public function onError($event)
{
$this->raiseEvent('onError',$event);
}
褰撲竴涓狿HP寮傚父閿欒鍙戠敓鏃跺彂璧枫
鍙互璁剧疆涓涓簨浠跺鐞handled锛
浜嬩欢鍙傛暟鐨勫睘鎬т负true琛ㄧず涓嶅啀闇瑕佽繘涓姝ュ鐞嗛敊璇
鍚﹀垯锛errorHandler
搴旂敤缁勪欢灏嗙户缁鐞嗛敊璇
|
public void onException(CExceptionEvent $event)
| ||
| $event | CExceptionEvent | 浜嬩欢鍙傛暟 |
public function onException($event)
{
$this->raiseEvent('onException',$event);
}
褰撲竴涓湭鎹曡幏鐨凱HP寮傚父鍙戠敓鏃跺彂璧枫
鍙互璁剧疆涓涓簨浠跺鐞handled锛
浜嬩欢鍙傛暟鐨勫睘鎬т负true琛ㄧず涓嶅啀闇瑕佽繘涓姝ュ鐞嗛敊璇
鍚﹀垯锛errorHandler
搴旂敤缁勪欢灏嗙户缁鐞嗛敊璇
|
abstract public void processRequest()
|
澶勭悊璇锋眰銆 杩欏疄闄呮槸璇峰鐞嗗伐浣滃凡缁忓畬鎴愮殑鍦版柟銆 娲剧敓绫诲簲璇ラ噸鍐欐鏂规硶銆
|
protected void registerCoreComponents()
|
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);
}
娉ㄥ唽鏍稿績搴旂敤缁勪欢銆
鍙傝
|
public void run()
|
public function run()
{
if($this->hasEventHandler('onBeginRequest'))
$this->onBeginRequest(new CEvent($this));
$this->processRequest();
if($this->hasEventHandler('onEndRequest'))
$this->onEndRequest(new CEvent($this));
}
杩愯搴旂敤绋嬪簭銆 姝ゆ柟娉曞姞杞介潤鎬佸簲鐢ㄧ粍浠躲 娲剧敓绫婚氬父閲嶅啓姝ゆ柟娉曞幓鍋氭洿澶氱壒瀹氬簲鐢ㄣ 璁颁綇瑕佽皟鐢ㄧ埗绫诲疄鐜帮紝浠ヤ娇闈欐佸簲鐢ㄧ粍浠惰鍔犺浇銆
|
public void saveGlobalState()
|
public function saveGlobalState()
{
if($this->_stateChanged)
{
$this->_stateChanged=false;
$this->detachEventHandler('onEndRequest',array($this,'saveGlobalState'));
$this->getStatePersister()->save($this->_globalState);
}
}
淇濆瓨鍏ㄥ眬鐘舵佹暟鎹埌鎸佷箙瀛樺偍銆
|
public void setBasePath(string $path)
| ||
| $path | string | 搴旂敤绋嬪簭鏍圭洰褰曘 |
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)));
}
璁剧疆搴旂敤绋嬪簭鏍圭洰褰曘 杩欎釜鏂规硶浠呭湪鏋勯犲嚱鏁版椂璋冪敤銆
|
public void setExtensionPath(string $path)
| ||
| $path | string | 绗笁鏂规墿灞曠洰褰曘 |
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);
}
璁剧疆绗笁鏂规墿灞曠洰褰曘
|
public void setGlobalState(string $key, mixed $value, mixed $defaultValue=NULL)
| ||
| $key | string | 瑕佷繚瀛樼殑鍊肩殑鍚嶇О |
| $value | mixed | 琚繚瀛樼殑鍏ㄥ眬鍊硷紝瀹冨繀椤绘槸搴忎緥鍖栫殑銆 |
| $defaultValue | mixed | 榛樿鍊笺傚鏋滆繖涓间笌鍏ㄥ眬鍊间笂鍚岋紝瀹冨皢娓呴櫎褰撳墠瀛樺偍銆 |
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涔嬮棿銆
纭繚杩欎釜鍊煎彲浠ュ簭渚嬪寲鍜屽弽搴忎緥鍖栥
鍙傝
|
public void setHomeUrl(string $value)
| ||
| $value | string | 璁剧疆涓婚〉URL |
public function setHomeUrl($value)
{
$this->_homeUrl=$value;
}
|
public void setId(string $id)
| ||
| $id | string | 搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆 |
璁剧疆搴旂敤绋嬪簭鍞竴鐨勬爣璇嗙銆
|
public void setLanguage(string $language)
| ||
| $language | string | 鐢ㄦ埛鐨勮瑷锛堜緥濡傦紝鈥榚n_US鈥欙紝鈥榸h_CN鈥欙級銆 濡傛灉涓簄ull锛屽皢浣跨敤sourceLanguage銆 |
public function setLanguage($language)
{
$this->_language=$language;
}
鎸囧畾搴旂敤绋嬪簭璇█銆
杩欎釜鏄簲鐢ㄧ▼搴忔樉绀烘渶缁堢敤鎴风殑璇█銆
濡傛灉涓簄ull锛屽畠灏嗕娇鐢source language銆
闄ら潪浣犵殑搴旂敤绋嬪簭闇瑕佹敮鎸佸璇█锛
鍚﹀垯浣犲簲璇ユ绘槸璁剧疆language涓簄ull锛屼互鏈澶у寲搴旂敤绋嬪簭鐨勬ц兘銆
|
public void setLocaleDataPath(string $value)
| ||
| $value | string | 鍖呭惈鏈湴鍖栨暟鎹殑鐩綍銆 |
public function setLocaleDataPath($value)
{
CLocale::$dataPath=$value;
}
璁剧疆鍖呭惈鏈湴鍖栨暟鎹殑鐩綍銆
|
public void setRuntimePath(string $path)
| ||
| $path | string | 瀛樺偍杩愯鏃舵枃浠剁洰褰曘 |
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;
}
璁剧疆瀛樺偍杩愯鏃舵枃浠剁洰褰曘
|
public void setTimeZone(string $value)
| ||
| $value | string | 搴旂敤绋嬪簭浣跨敤鐨勬椂鍖恒 |
public function setTimeZone($value)
{
date_default_timezone_set($value);
}
璁剧疆搴旂敤绋嬪簭鎵浣跨敤鐨勬椂鍖恒 杩欎釜涓涓畝鍗曠殑PHP鍑芥暟date_default_timezone_set()鐨勫皝瑁呫