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 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 |
灞炴ц缁
the asset manager component
the authorization manager component
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.
Returns the client script manager.
the currently active controller
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.
the directory that contains the controller classes. Defaults to 'protected/controllers'.
the route of the default controller, action or module. Defaults to 'site'.
the application-wide layout. Defaults to 'main' (relative to layoutPath). If this is false, then no layout will be used.
the root directory of layout files. Defaults to 'protected/views/layouts'.
the session component
the root directory of system view files. Defaults to 'protected/views/system'.
the theme used currently. Null if no theme is being used.
the theme manager.
the user session information
the root directory of view files. Defaults to 'protected/views'.
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.
Returns the widget factory.
鏂规硶璇︾粏
public void afterControllerAction(CController $controller, CAction $action)
| ||
$controller | CController | the controller |
$action | CAction | the action |
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.
public boolean beforeControllerAction(CController $controller, CAction $action)
| ||
$controller | CController | the controller |
$action | CAction | the action |
{return} | boolean | whether the action should be executed. |
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.
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. |
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:
- If the first segment is found in controllerMap, the corresponding controller configuration will be used to create the controller;
- If the first segment is found to be a module ID, the corresponding module will be used to create the controller;
- 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".
public CWebModule findModule(string $id)
| ||
$id | string | module ID |
{return} | CWebModule | the module that has the specified ID. Null if no module is found. |
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.
public CAssetManager getAssetManager()
| ||
{return} | CAssetManager | the asset manager component |
public function getAssetManager()
{
return $this->getComponent('assetManager');
}
public IAuthManager getAuthManager()
| ||
{return} | IAuthManager | the authorization manager component |
public function getAuthManager()
{
return $this->getComponent('authManager');
}
public CClientScript getClientScript()
| ||
{return} | CClientScript | the client script manager |
public function getClientScript()
{
return $this->getComponent('clientScript');
}
Returns the client script manager.
public CController getController()
| ||
{return} | CController | the currently active controller |
public function getController()
{
return $this->_controller;
}
public string getControllerPath()
| ||
{return} | string | the directory that contains the controller classes. Defaults to 'protected/controllers'. |
public function getControllerPath()
{
if($this->_controllerPath!==null)
return $this->_controllerPath;
else
return $this->_controllerPath=$this->getBasePath().DIRECTORY_SEPARATOR.'controllers';
}
public string getLayoutPath()
| ||
{return} | string | the root directory of layout files. Defaults to 'protected/views/layouts'. |
public function getLayoutPath()
{
if($this->_layoutPath!==null)
return $this->_layoutPath;
else
return $this->_layoutPath=$this->getViewPath().DIRECTORY_SEPARATOR.'layouts';
}
public CHttpSession getSession()
| ||
{return} | CHttpSession | the session component |
public function getSession()
{
return $this->getComponent('session');
}
public string getSystemViewPath()
| ||
{return} | string | the root directory of system view files. Defaults to 'protected/views/system'. |
public function getSystemViewPath()
{
if($this->_systemViewPath!==null)
return $this->_systemViewPath;
else
return $this->_systemViewPath=$this->getViewPath().DIRECTORY_SEPARATOR.'system';
}
public CTheme getTheme()
| ||
{return} | CTheme | the theme used currently. Null if no theme is being used. |
public function getTheme()
{
if(is_string($this->_theme))
$this->_theme=$this->getThemeManager()->getTheme($this->_theme);
return $this->_theme;
}
public CThemeManager getThemeManager()
| ||
{return} | CThemeManager | the theme manager. |
public function getThemeManager()
{
return $this->getComponent('themeManager');
}
public CWebUser getUser()
| ||
{return} | CWebUser | the user session information |
public function getUser()
{
return $this->getComponent('user');
}
public string getViewPath()
| ||
{return} | string | the root directory of view files. Defaults to 'protected/views'. |
public function getViewPath()
{
if($this->_viewPath!==null)
return $this->_viewPath;
else
return $this->_viewPath=$this->getBasePath().DIRECTORY_SEPARATOR.'views';
}
public IViewRenderer getViewRenderer()
| ||
{return} | IViewRenderer | the view renderer. |
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.
public IWidgetFactory getWidgetFactory()
| ||
{return} | IWidgetFactory | the widget factory |
public function getWidgetFactory()
{
return $this->getComponent('widgetFactory');
}
Returns the widget factory.
protected void init()
|
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.
protected string parseActionParams(string $pathInfo)
| ||
$pathInfo | string | path info |
{return} | string | action ID |
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.
public void processRequest()
|
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.
protected void registerCoreComponents()
|
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.
鍙傝
public void runController(string $route)
| ||
$route | string | the route of the current request. See createController for more details. |
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.
public void setController(CController $value)
| ||
$value | CController | the currently active controller |
public function setController($value)
{
$this->_controller=$value;
}
public void setControllerPath(string $value)
| ||
$value | string | the directory that contains the controller classes. |
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)));
}
public void setLayoutPath(string $path)
| ||
$path | string | the root directory of layout files. |
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)));
}
public void setSystemViewPath(string $path)
| ||
$path | string | the root directory of system view files. |
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)));
}
public void setTheme(string $value)
| ||
$value | string | the theme name |
public function setTheme($value)
{
$this->_theme=$value;
}
public void setViewPath(string $path)
| ||
$path | string | the root directory of view files. |
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)));
}