Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • BaseDocsMassAction
  • CApplication
  • CApplicationComponent
  • CBehavior
  • CComponent
  • CEnumerable
  • CErrorEvent
  • CErrorHandler
  • CEvent
  • CExceptionEvent
  • CModel
  • CModelBehavior
  • CModelEvent
  • CModule
  • CommonFieldsBehavior
  • CSecurityManager
  • CStatePersister
  • Expression
  • MassAction
  • MassAddToList
  • MassCompleteAction
  • MassMoveFileSysObjToFolder
  • MassRemoveFromList
  • MassRenameFileSysObj
  • MassUncompleteAction
  • MobileRecentItems
  • ModulePanelItem
  • NewListFromSelection
  • PanelItem
  • QuickCRUDBehavior
  • RecentItemPanelItem
  • ServiceRoutingBehavior
  • SettingsPanelItem
  • X2AddressBehavior
  • X2AuthCache
  • X2BaseListViewBehavior

Interfaces

  • IAction
  • IApplicationComponent
  • IAuthManager
  • IBehavior
  • IFilter
  • IStatePersister
  • IUserIdentity
  • IViewRenderer
  • IWebServiceProvider
  • IWebUser

Exceptions

  • CException
  • CHttpException
  • TwitterFeedWidgetException
  • Overview
  • Package
  • Class
  • Tree

Class CApplication

CApplication is the base class for all application classes.

An application serves as the global context that the user request is being processed. It manages a set of application components that provide specific functionalities to the whole application.

The core application components provided by CApplication are the following:
  • getErrorHandler errorHandler: handles PHP errors and uncaught exceptions. This application component is dynamically loaded when needed.
  • getSecurityManager securityManager: provides security-related services, such as hashing, encryption. This application component is dynamically loaded when needed.
  • getStatePersister statePersister: provides global state persistence method. This application component is dynamically loaded when needed.
  • getCache cache: provides caching feature. This application component is disabled by default.
  • getMessages messages: provides the message source for translating application messages. This application component is dynamically loaded when needed.
  • getCoreMessages coreMessages: provides the message source for translating Yii framework messages. This application component is dynamically loaded when needed.
  • getUrlManager urlManager: provides URL construction as well as parsing functionality. This application component is dynamically loaded when needed.
  • getRequest request: represents the current HTTP request by encapsulating the $_SERVER variable and managing cookies sent from and sent to the user. This application component is dynamically loaded when needed.
  • getFormat format: provides a set of commonly used data formatting methods. This application component is dynamically loaded when needed.
CApplication will undergo the following lifecycles when processing a user request:
  1. load application configuration;
  2. set up error handling;
  3. load static application components;
  4. CApplication::onBeginRequest(): preprocess the user request;
  5. CApplication::processRequest(): process the user request;
  6. CApplication::onEndRequest(): postprocess the user request;

Starting from lifecycle 3, if a PHP error or an uncaught exception occurs, the application will switch to its error handling logic and jump to step 6 afterwards.

CComponent
Extended by CModule
Extended by CApplication

Direct known subclasses

CConsoleApplication, CWebApplication

Indirect known subclasses

X2WebApplication
Abstract
Package: system\base
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/base/CApplication.php
Methods summary
abstract public
# processRequest( )

Processes the request. This is the place where the actual request processing work is done. Derived classes should override this method.

Processes the request. This is the place where the actual request processing work is done. Derived classes should override this method.

public
# __construct( mixed $config = null )

Constructor.

Constructor.

Parameters

$config
mixed
$config application configuration. If a string, it is treated as the path of the file that contains the configuration; If an array, it is the actual configuration information. Please make sure you specify the getBasePath basePath property in the configuration, which should point to the directory containing all application logic, template and data. If not, the directory will be defaulted to 'protected'.

Overrides

CModule::__construct()
public
# run( )

Runs the application. This method loads static application components. Derived classes usually overrides this method to do more application-specific tasks. Remember to call the parent implementation so that static application components are loaded.

Runs the application. This method loads static application components. Derived classes usually overrides this method to do more application-specific tasks. Remember to call the parent implementation so that static application components are loaded.

public
# end( integer $status = 0, boolean $exit = true )

Terminates the application. This method replaces PHP's exit() function by calling CApplication::onEndRequest() before exiting.

Terminates the application. This method replaces PHP's exit() function by calling CApplication::onEndRequest() before exiting.

Parameters

$status
integer
$status exit status (value 0 means normal exit while other values mean abnormal exit).
$exit
boolean
$exit whether to exit the current request. This parameter has been available since version 1.1.5. It defaults to true, meaning the PHP's exit() function will be called at the end of this method.
public
# onBeginRequest( CEvent $event )

Raised right BEFORE the application processes the request.

Raised right BEFORE the application processes the request.

Parameters

$event
CEvent
$event the event parameter
public
# onEndRequest( CEvent $event )

Raised right AFTER the application processes the request.

Raised right AFTER the application processes the request.

Parameters

$event
CEvent
$event the event parameter
public string
# getId( )

Returns the unique identifier for the application.

Returns the unique identifier for the application.

Returns

string
the unique identifier for the application.

Overrides

CModule::getId()
public
# setId( string $id )

Sets the unique identifier for the application.

Sets the unique identifier for the application.

Parameters

$id
string
$id the unique identifier for the application.

Overrides

CModule::setId()
public string
# getBasePath( )

Returns the root path of the application.

Returns the root path of the application.

Returns

string
the root directory of the application. Defaults to 'protected'.

Overrides

CModule::getBasePath()
public
# setBasePath( string $path )

Sets the root directory of the application. This method can only be invoked at the begin of the constructor.

Sets the root directory of the application. This method can only be invoked at the begin of the constructor.

Parameters

$path
string
$path the root directory of the application.

Throws

CException
if the directory does not exist.

Overrides

CModule::setBasePath()
public string
# getRuntimePath( )

Returns the directory that stores runtime files.

Returns the directory that stores runtime files.

Returns

string
the directory that stores runtime files. Defaults to 'protected/runtime'.
public
# setRuntimePath( string $path )

Sets the directory that stores runtime files.

Sets the directory that stores runtime files.

Parameters

$path
string
$path the directory that stores runtime files.

Throws

CException
if the directory does not exist or is not writable
public string
# getExtensionPath( )

Returns the root directory that holds all third-party extensions.

Returns the root directory that holds all third-party extensions.

Returns

string
the directory that contains all extensions. Defaults to the 'extensions' directory under 'protected'.
public
# setExtensionPath( string $path )

Sets the root directory that holds all third-party extensions.

Sets the root directory that holds all third-party extensions.

Parameters

$path
string
$path the directory that contains all third-party extensions.

Throws

CException
if the directory does not exist
public string
# getLanguage( )

Returns the language that the user is using and the application should be targeted to.

Returns the language that the user is using and the application should be targeted to.

Returns

string
the language that the user is using and the application should be targeted to. Defaults to the sourceLanguage source language.
public
# setLanguage( string $language )

Specifies which language the application is targeted to.

Specifies which language the application is targeted to.

This is the language that the application displays to end users. If set null, it uses the sourceLanguage source language.

Unless your application needs to support multiple languages, you should always set this language to null to maximize the application's performance.

Parameters

$language
string
$language the user language (e.g. 'en_US', 'zh_CN'). If it is null, the CApplication::$sourceLanguage will be used.
public string
# getTimeZone( )

Returns the time zone used by this application. This is a simple wrapper of PHP function date_default_timezone_get().

Returns the time zone used by this application. This is a simple wrapper of PHP function date_default_timezone_get().

Returns

string
the time zone used by this application.

See

http://php.net/manual/en/function.date-default-timezone-get.php
public
# setTimeZone( string $value )

Sets the time zone used by this application. This is a simple wrapper of PHP function date_default_timezone_set().

Sets the time zone used by this application. This is a simple wrapper of PHP function date_default_timezone_set().

Parameters

$value
string
$value the time zone used by this application.

See

http://php.net/manual/en/function.date-default-timezone-set.php
public string
# findLocalizedFile( string $srcFile, string $srcLanguage = null, string $language = null )

Returns the localized version of a specified file.

Returns the localized version of a specified file.

The searching is based on the specified language code. In particular, a file with the same name will be looked for under the subdirectory named as the locale ID. For example, given the file "path/to/view.php" and locale ID "zh_cn", the localized file will be looked for as "path/to/zh_cn/view.php". If the file is not found, the original file will be returned.

For consistency, it is recommended that the locale ID is given in lower case and in the format of LanguageID_RegionID (e.g. "en_us").

Parameters

$srcFile
string
$srcFile the original file
$srcLanguage
string
$srcLanguage the language that the original file is in. If null, the application sourceLanguage source language is used.
$language
string
$language the desired language that the file should be localized to. If null, the getLanguage application language will be used.

Returns

string
the matching localized file. The original file is returned if no localized version is found or if source language is the same as the desired language.
public an
# getLocale( string $localeID = null )

Returns the locale instance.

Returns the locale instance.

Parameters

$localeID
string
$localeID the locale ID (e.g. en_US). If null, the getLanguage application language ID will be used.

Returns

an
instance of CLocale
public string
# getLocaleDataPath( )

Returns the directory that contains the locale data.

Returns the directory that contains the locale data.

Returns

string
the directory that contains the locale data. It defaults to 'framework/i18n/data'.

Since

1.1.0
public
# setLocaleDataPath( string $value )

Sets the directory that contains the locale data.

Sets the directory that contains the locale data.

Parameters

$value
string
$value the directory that contains the locale data.

Since

1.1.0
public CNumberFormatter
# getNumberFormatter( )

Returns

CNumberFormatter
the locale-dependent number formatter. The current getLocale application locale will be used.
public CDateFormatter
# getDateFormatter( )

Returns the locale-dependent date formatter.

Returns the locale-dependent date formatter.

Returns

CDateFormatter
the locale-dependent date formatter. The current getLocale application locale will be used.
public CDbConnection
# getDb( )

Returns the database connection component.

Returns the database connection component.

Returns

CDbConnection
the database connection
public CErrorHandler
# getErrorHandler( )

Returns the error handler component.

Returns the error handler component.

Returns

CErrorHandler
the error handler application component.
public CSecurityManager
# getSecurityManager( )

Returns the security manager component.

Returns the security manager component.

Returns

CSecurityManager
the security manager application component.
public CStatePersister
# getStatePersister( )

Returns the state persister component.

Returns the state persister component.

Returns

CStatePersister
the state persister application component.
public CCache
# getCache( )

Returns the cache component.

Returns the cache component.

Returns

CCache
the cache application component. Null if the component is not enabled.
public CPhpMessageSource
# getCoreMessages( )

Returns the core message translations component.

Returns the core message translations component.

Returns

CPhpMessageSource
the core message translations
public CMessageSource
# getMessages( )

Returns the application message translations component.

Returns the application message translations component.

Returns

CMessageSource
the application message translations
public CHttpRequest
# getRequest( )

Returns the request component.

Returns the request component.

Returns

CHttpRequest
the request component
public CUrlManager
# getUrlManager( )

Returns the URL manager component.

Returns the URL manager component.

Returns

CUrlManager
the URL manager component
public CController
# getController( )

Returns

CController
the currently active controller. Null is returned in this base class.

Since

1.1.8
public string
# createUrl( string $route, array $params = array(), string $ampersand = '&' )

Creates a relative URL based on the given controller and action information.

Creates a relative URL based on the given controller and action information.

Parameters

$route
string
$route the URL route. This should be in the format of 'ControllerID/ActionID'.
$params
array
$params additional GET parameters (name=>value). Both the name and value will be URL-encoded.
$ampersand
string
$ampersand the token separating name-value pairs in the URL.

Returns

string
the constructed URL
public string
# createAbsoluteUrl( string $route, array $params = array(), string $schema = '', string $ampersand = '&' )

Creates an absolute URL based on the given controller and action information.

Creates an absolute URL based on the given controller and action information.

Parameters

$route
string
$route the URL route. This should be in the format of 'ControllerID/ActionID'.
$params
array
$params additional GET parameters (name=>value). Both the name and value will be URL-encoded.
$schema
string
$schema schema to use (e.g. http, https). If empty, the schema used for the current request will be used.
$ampersand
string
$ampersand the token separating name-value pairs in the URL.

Returns

string
the constructed URL
public string
# getBaseUrl( boolean $absolute = false )

Returns the relative URL for the application. This is a shortcut method to CHttpRequest::getBaseUrl().

Returns the relative URL for the application. This is a shortcut method to CHttpRequest::getBaseUrl().

Parameters

$absolute
boolean
$absolute whether to return an absolute URL. Defaults to false, meaning returning a relative one.

Returns

string
the relative URL for the application

See

CHttpRequest::getBaseUrl()
public string
# getHomeUrl( )

Returns

string
the homepage URL
public
# setHomeUrl( string $value )

Parameters

$value
string
$value the homepage URL
public mixed
# getGlobalState( string $key, mixed $defaultValue = null )

Returns a global value.

Returns a global value.

A global value is one that is persistent across users sessions and requests.

Parameters

$key
string
$key the name of the value to be returned
$defaultValue
mixed
$defaultValue the default value. If the named global value is not found, this will be returned instead.

Returns

mixed
the named global value

See

CApplication::setGlobalState()
public
# setGlobalState( string $key, mixed $value, mixed $defaultValue = null )

Sets a global value.

Sets a global value.

A global value is one that is persistent across users sessions and requests. Make sure that the value is serializable and unserializable.

Parameters

$key
string
$key the name of the value to be saved
$value
mixed
$value the global value to be saved. It must be serializable.
$defaultValue
mixed
$defaultValue the default value. If the named global value is the same as this value, it will be cleared from the current storage.

See

CApplication::getGlobalState()
public
# clearGlobalState( string $key )

Clears a global value.

Clears a global value.

The value cleared will no longer be available in this request and the following requests.

Parameters

$key
string
$key the name of the value to be cleared
public
# loadGlobalState( )

Loads the global state data from persistent storage.

Loads the global state data from persistent storage.

Throws

CException
if the state persister is not available

See

CApplication::getStatePersister()
public
# saveGlobalState( )

Saves the global state data into persistent storage.

Saves the global state data into persistent storage.

Throws

CException
if the state persister is not available

See

CApplication::getStatePersister()
public
# handleException( Exception $exception )

Handles uncaught PHP exceptions.

Handles uncaught PHP exceptions.

This method is implemented as a PHP exception handler. It requires that constant YII_ENABLE_EXCEPTION_HANDLER be defined true.

This method will first raise an CApplication::onException() event. If the exception is not handled by any event handler, it will call getErrorHandler errorHandler to process the exception.

The application will be terminated by this method.

Parameters

$exception
Exception
$exception exception that is not caught
public
# handleError( integer $code, string $message, string $file, integer $line )

Handles PHP execution errors such as warnings, notices.

Handles PHP execution errors such as warnings, notices.

This method is implemented as a PHP error handler. It requires that constant YII_ENABLE_ERROR_HANDLER be defined true.

This method will first raise an CApplication::onError() event. If the error is not handled by any event handler, it will call getErrorHandler errorHandler to process the error.

The application will be terminated by this method.

Parameters

$code
integer
$code the level of the error raised
$message
string
$message the error message
$file
string
$file the filename that the error was raised in
$line
integer
$line the line number the error was raised at
public
# onException( CExceptionEvent $event )

Raised when an uncaught PHP exception occurs.

Raised when an uncaught PHP exception occurs.

An event handler can set the CExceptionEvent::handled handled property of the event parameter to be true to indicate no further error handling is needed. Otherwise, the getErrorHandler errorHandler application component will continue processing the error.

Parameters

$event
CExceptionEvent
$event event parameter
public
# onError( CErrorEvent $event )

Raised when a PHP execution error occurs.

Raised when a PHP execution error occurs.

An event handler can set the CErrorEvent::handled handled property of the event parameter to be true to indicate no further error handling is needed. Otherwise, the getErrorHandler errorHandler application component will continue processing the error.

Parameters

$event
CErrorEvent
$event event parameter
public
# displayError( integer $code, string $message, string $file, string $line )

Displays the captured PHP error. This method displays the error in HTML when there is no active error handler.

Displays the captured PHP error. This method displays the error in HTML when there is no active error handler.

Parameters

$code
integer
$code error code
$message
string
$message error message
$file
string
$file error file
$line
string
$line error line
public
# displayException( Exception $exception )

Displays the uncaught PHP exception. This method displays the exception in HTML when there is no active error handler.

Displays the uncaught PHP exception. This method displays the exception in HTML when there is no active error handler.

Parameters

$exception
Exception
$exception the uncaught exception
protected
# initSystemHandlers( )

Initializes the error handlers.

Initializes the error handlers.

protected
# registerCoreComponents( )

Registers the core application components.

Registers the core application components.

See

CModule::setComponents()
Methods inherited from CModule
__get(), __isset(), configure(), getComponent(), getComponents(), getModule(), getModulePath(), getModules(), getParams(), getParentModule(), hasComponent(), hasModule(), init(), preinit(), preloadComponents(), setAliases(), setComponent(), setComponents(), setImport(), setModulePath(), setModules(), setParams()
Methods inherited from CComponent
__call(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Properties summary
public string $name 'My Application'
#

the application name. Defaults to 'My Application'.

the application name. Defaults to 'My Application'.

public string $charset 'UTF-8'
#

the charset currently used for the application. Defaults to 'UTF-8'.

the charset currently used for the application. Defaults to 'UTF-8'.

public string $sourceLanguage 'en_us'
#

the language that the application is written in. This mainly refers to the language that the messages and view files are in. Defaults to 'en_us' (US English).

the language that the application is written in. This mainly refers to the language that the messages and view files are in. Defaults to 'en_us' (US English).

public string $localeClass 'CLocale'
#

the class used to get locale data. Defaults to 'CLocale'.

the class used to get locale data. Defaults to 'CLocale'.

Properties inherited from CModule
$behaviors, $preload
Magic properties summary
public string $id
#

The unique identifier for the application.

The unique identifier for the application.

public string $basePath
#

The root directory of the application. Defaults to 'protected'.

The root directory of the application. Defaults to 'protected'.

public string $runtimePath
#

The directory that stores runtime files. Defaults to 'protected/runtime'.

The directory that stores runtime files. Defaults to 'protected/runtime'.

public string $extensionPath
#

The directory that contains all extensions. Defaults to the 'extensions' directory under 'protected'.

The directory that contains all extensions. Defaults to the 'extensions' directory under 'protected'.

public string $language
#

The language that the user is using and the application should be targeted to. Defaults to the sourceLanguage source language.

The language that the user is using and the application should be targeted to. Defaults to the sourceLanguage source language.

public string $timeZone
#

The time zone used by this application.

The time zone used by this application.

public CLocale $locale
#

The locale instance.

The locale instance.

public string $localeDataPath
#

The directory that contains the locale data. It defaults to 'framework/i18n/data'.

The directory that contains the locale data. It defaults to 'framework/i18n/data'.

public CNumberFormatter $numberFormatter
#

The locale-dependent number formatter. The current getLocale application locale will be used.

The locale-dependent number formatter. The current getLocale application locale will be used.

public CDateFormatter $dateFormatter
#

The locale-dependent date formatter. The current getLocale application locale will be used.

The locale-dependent date formatter. The current getLocale application locale will be used.

public CDbConnection $db
#

The database connection.

The database connection.

public CErrorHandler $errorHandler
#

The error handler application component.

The error handler application component.

public CSecurityManager $securityManager
#

The security manager application component.

The security manager application component.

public CStatePersister $statePersister
#

The state persister application component.

The state persister application component.

public CCache $cache
#

The cache application component. Null if the component is not enabled.

The cache application component. Null if the component is not enabled.

public CPhpMessageSource $coreMessages
#

The core message translations.

The core message translations.

public CMessageSource $messages
#

The application message translations.

The application message translations.

public CHttpRequest $request
#

The request component.

The request component.

public CUrlManager $urlManager
#

The URL manager component.

The URL manager component.

public CController $controller
#

The currently active controller. Null is returned in this base class.

The currently active controller. Null is returned in this base class.

public string $baseUrl
#

The relative URL for the application.

The relative URL for the application.

public string $homeUrl
#

The homepage URL.

The homepage URL.

Magic properties inherited from CModule
$aliases, $components, $import, $modulePath, $modules, $params, $parentModule
API documentation generated by ApiGen 2.8.0