Package | system.base |
---|---|
Inheritance | abstract class CApplication » CModule » CComponent |
Subclasses | CConsoleApplication, CWebApplication |
Since | 1.0 |
Version | $Id$ |
Source Code | framework/base/CApplication.php |
Property | Type | Description | Defined By |
---|---|---|---|
basePath | string | the root directory of the application. | CApplication |
behaviors | array | the behaviors that should be attached to the module. | CModule |
cache | CCache | the cache application component. | CApplication |
charset | string | the charset currently used for the application. | CApplication |
components | array | the currently loaded components (indexed by their IDs) | CModule |
coreMessages | CPhpMessageSource | the core message translations | CApplication |
dateFormatter | CDateFormatter | the locale-dependent date formatter. | CApplication |
db | CDbConnection | the database connection | CApplication |
errorHandler | CErrorHandler | the error handler application component. | CApplication |
extensionPath | string | Returns the root directory that holds all third-party extensions. | CApplication |
id | string | a unique identifier for the application. | CApplication |
language | string | the language that the user is using and the application should be targeted to. | CApplication |
locale | CLocale | the locale instance | CApplication |
messages | CMessageSource | the application message translations | CApplication |
modulePath | string | the directory that contains the application modules. | CModule |
modules | array | the configuration of the currently installed modules (module ID => configuration) | CModule |
name | string | the application name. | CApplication |
numberFormatter | CNumberFormatter | the locale-dependent number formatter. | CApplication |
params | CAttributeCollection | the list of user-defined parameters | CModule |
parentModule | CModule | the parent module. | CModule |
preload | array | the IDs of the application components that should be preloaded. | CModule |
request | CHttpRequest | the request component | CApplication |
runtimePath | string | the directory that stores runtime files. | CApplication |
securityManager | CSecurityManager | the security manager application component. | CApplication |
sourceLanguage | string | the language that the application is written in. | CApplication |
statePersister | CStatePersister | the state persister application component. | CApplication |
timeZone | string | Returns the time zone used by this application. | CApplication |
urlManager | CUrlManager | the URL manager component | CApplication |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | Constructor. | CApplication |
__get() | Getter magic method. | CModule |
__isset() | Checks if a property value is null. | CModule |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
clearGlobalState() | Clears a global value. | CApplication |
configure() | Configures the module with the specified configuration. | CModule |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
displayError() | Displays the captured PHP error. | CApplication |
displayException() | Displays the uncaught PHP exception. | CApplication |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
end() | Terminates the application. | CApplication |
findLocalizedFile() | Returns the localized version of a specified file. | CApplication |
getBasePath() | Returns the root directory of the application. Defaults to 'protected'. | CApplication |
getCache() | Returns the cache application component. Null if the component is not enabled. | CApplication |
getComponent() | Retrieves the named application component. | CModule |
getComponents() | Returns the currently loaded components (indexed by their IDs) | CModule |
getCoreMessages() | Returns the core message translations | CApplication |
getDateFormatter() | Returns the locale-dependent date formatter. The current application locale will be used. | CApplication |
getDb() | Returns the database connection | CApplication |
getErrorHandler() | Returns the error handler application component. | CApplication |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getExtensionPath() | Returns the root directory that holds all third-party extensions. | CApplication |
getGlobalState() | Returns a global value. | CApplication |
getId() | Returns a unique identifier for the application. | CApplication |
getLanguage() | Returns the language that the user is using and the application should be targeted to. Defaults to the source language. | CApplication |
getLocale() | Returns the locale instance | CApplication |
getMessages() | Returns the application message translations | CApplication |
getModule() | Retrieves the named application module. | CModule |
getModulePath() | Returns the directory that contains the application modules. Defaults to the 'modules' subdirectory of basePath. | CModule |
getModules() | Returns the configuration of the currently installed modules (module ID => configuration) | CModule |
getNumberFormatter() | Returns the locale-dependent number formatter. The current application locale will be used. | CApplication |
getParams() | Returns the list of user-defined parameters | CModule |
getParentModule() | Returns the parent module. Null if this module does not have a parent. | CModule |
getRequest() | Returns the request component | CApplication |
getRuntimePath() | Returns the directory that stores runtime files. Defaults to 'protected/runtime'. | CApplication |
getSecurityManager() | Returns the security manager application component. | CApplication |
getStatePersister() | Returns the state persister application component. | CApplication |
getTimeZone() | Returns the time zone used by this application. | CApplication |
getUrlManager() | Returns the URL manager component | CApplication |
handleError() | Handles PHP execution errors such as warnings, notices. | CApplication |
handleException() | Handles uncaught PHP exceptions. | CApplication |
hasComponent() | Determines whether the named application component exists (including both loaded and disabled.) | CModule |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
onBeginRequest() | Raised right BEFORE the application processes the request. | CApplication |
onEndRequest() | Raised right AFTER the application processes the request. | CApplication |
onError() | Raised when a PHP execution error occurs. | CApplication |
onException() | Raised when an uncaught PHP exception occurs. | CApplication |
processRequest() | Processes the request. | CApplication |
raiseEvent() | Raises an event. | CComponent |
run() | Runs the application. | CApplication |
setAliases() | Defines the root aliases. | CModule |
setBasePath() | Sets the root directory of the application. | CApplication |
setComponent() | Puts a component under the management of the module. | CModule |
setComponents() | Sets the application components. | CModule |
setExtensionPath() | Sets the directory that contains all third-party extensions. | CApplication |
setGlobalState() | Sets a global value. | CApplication |
setId() | Sets a unique identifier for the application. | CApplication |
setImport() | Sets the aliases that are used in the module. | CModule |
setLanguage() | Specifies which language the application is targeted to. | CApplication |
setModulePath() | Sets the directory that contains the application modules. | CModule |
setModules() | Configures the sub-modules of this module. | CModule |
setParams() | Sets user-defined parameters. This should be in name-value pairs. | CModule |
setRuntimePath() | Sets the directory that stores runtime files. | CApplication |
setTimeZone() | Sets the time zone used by this application. | CApplication |
Method | Description | Defined By |
---|---|---|
init() | Initializes the module. | CModule |
initSystemHandlers() | Initializes the class autoloader and error handlers. | CApplication |
loadGlobalState() | Loads the global state data from persistent storage. | CApplication |
preinit() | Preinitializes the module. | CModule |
preloadComponents() | Loads static application components. | CModule |
registerCoreComponents() | Registers the core application components. | CApplication |
saveGlobalState() | Saves the global state data into persistent storage. | CApplication |
Event | Description | Defined By |
---|---|---|
onBeginRequest | Raised right BEFORE the application processes the request. | CApplication |
onEndRequest | Raised right AFTER the application processes the request. | CApplication |
onException | Raised when an uncaught PHP exception occurs. | CApplication |
onError | Raised when a PHP execution error occurs. | CApplication |
the root directory of the application. Defaults to 'protected'.
the cache application component. Null if the component is not enabled.
the charset currently used for the application. Defaults to 'UTF-8'.
the core message translations
the locale-dependent date formatter. The current application locale will be used.
the database connection
the error handler application component.
Returns the root directory that holds all third-party extensions.
a unique identifier for the application.
the language that the user is using and the application should be targeted to. Defaults to the source language.
the locale instance
the application message translations
the application name. Defaults to 'My Application'.
the locale-dependent number formatter. The current application locale will be used.
the request component
the directory that stores runtime files. Defaults to 'protected/runtime'.
the security manager application component.
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 state persister application component.
Returns the time zone used by this application. This is a simple wrapper of PHP function date_default_timezone_get().
the URL manager component
public void __construct(mixed $config=NULL)
| ||
$config | mixed | 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 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'. |
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();
}
Constructor.
public void clearGlobalState(string $key)
| ||
$key | string | the name of the value to be cleared |
public function clearGlobalState($key)
{
if($this->_globalState===null)
$this->loadGlobalState();
if(isset($this->_globalState[$key]))
{
$this->_stateChanged=true;
unset($this->_globalState[$key]);
}
}
Clears a global value.
The value cleared will no longer be available in this request and the following requests.
public void displayError(integer $code, string $message, string $file, string $line)
| ||
$code | integer | error code |
$message | string | error message |
$file | string | error file |
$line | string | error line |
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>';
debug_print_backtrace();
echo '</pre>';
}
else
{
echo "<h1>PHP Error [$code]</h1>\n";
echo "<p>$message</p>\n";
}
}
Displays the captured PHP error. This method displays the error in HTML when there is no active error handler.
public void displayException(Exception $exception)
| ||
$exception | Exception | the uncaught 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>';
}
}
Displays the uncaught PHP exception. This method displays the exception in HTML when there is no active error handler.
public void end(integer $status=0)
| ||
$status | integer | exit status (value 0 means normal exit while other values mean abnormal exit). |
public function end($status=0)
{
if($this->hasEventHandler('onEndRequest'))
$this->onEndRequest(new CEvent($this));
exit($status);
}
Terminates the application. This method replaces PHP's exit() function by calling onEndRequest before exiting.
public string findLocalizedFile(string $srcFile, string $srcLanguage=NULL, string $language=NULL)
| ||
$srcFile | string | the original file |
$srcLanguage | string | the language that the original file is in. If null, the application source language is used. |
$language | string | the desired language that the file should be localized to. If null, the application language will be used. |
{return} | 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 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;
}
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").
public string getBasePath()
| ||
{return} | string | the root directory of the application. Defaults to 'protected'. |
public function getBasePath()
{
return $this->_basePath;
}
public CCache getCache()
| ||
{return} | CCache | the cache application component. Null if the component is not enabled. |
public function getCache()
{
return $this->getComponent('cache');
}
public CPhpMessageSource getCoreMessages()
| ||
{return} | CPhpMessageSource | the core message translations |
public function getCoreMessages()
{
return $this->getComponent('coreMessages');
}
public CDateFormatter getDateFormatter()
| ||
{return} | CDateFormatter | the locale-dependent date formatter. The current application locale will be used. |
public function getDateFormatter()
{
return $this->getLocale()->getDateFormatter();
}
public CDbConnection getDb()
| ||
{return} | CDbConnection | the database connection |
public function getDb()
{
return $this->getComponent('db');
}
public CErrorHandler getErrorHandler()
| ||
{return} | CErrorHandler | the error handler application component. |
public function getErrorHandler()
{
return $this->getComponent('errorHandler');
}
public string getExtensionPath()
| ||
{return} | string | the directory that contains all extensions. Defaults to the 'extensions' directory under 'protected'. |
public function getExtensionPath()
{
return Yii::getPathOfAlias('ext');
}
Returns the root directory that holds all third-party extensions.
public mixed getGlobalState(string $key, mixed $defaultValue=NULL)
| ||
$key | string | the name of the value to be returned |
$defaultValue | mixed | the default value. If the named global value is not found, this will be returned instead. |
{return} | mixed | the named global value |
public function getGlobalState($key,$defaultValue=null)
{
if($this->_globalState===null)
$this->loadGlobalState();
if(isset($this->_globalState[$key]))
return $this->_globalState[$key];
else
return $defaultValue;
}
Returns a global value.
A global value is one that is persistent across users sessions and requests.
public string getId()
| ||
{return} | string | a unique identifier for the application. |
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 | the language that the user is using and the application should be targeted to. Defaults to the source language. |
public function getLanguage()
{
return $this->_language===null ? $this->sourceLanguage : $this->_language;
}
public CLocale getLocale(string $localeID=NULL)
| ||
$localeID | string | locale ID (e.g. en_US). If null, the application language ID will be used. |
{return} | CLocale | the locale instance |
public function getLocale($localeID=null)
{
return CLocale::getInstance($localeID===null?$this->getLanguage():$localeID);
}
public CMessageSource getMessages()
| ||
{return} | CMessageSource | the application message translations |
public function getMessages()
{
return $this->getComponent('messages');
}
public CNumberFormatter getNumberFormatter()
| ||
{return} | CNumberFormatter | the locale-dependent number formatter. The current application locale will be used. |
public function getNumberFormatter()
{
return $this->getLocale()->getNumberFormatter();
}
public CHttpRequest getRequest()
| ||
{return} | CHttpRequest | the request component |
public function getRequest()
{
return $this->getComponent('request');
}
public string getRuntimePath()
| ||
{return} | string | the directory that stores runtime files. Defaults to 'protected/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 | the security manager application component. |
public function getSecurityManager()
{
return $this->getComponent('securityManager');
}
public CStatePersister getStatePersister()
| ||
{return} | CStatePersister | the state persister application component. |
public function getStatePersister()
{
return $this->getComponent('statePersister');
}
public string getTimeZone()
| ||
{return} | string | the time zone used by this application. |
public function getTimeZone()
{
return date_default_timezone_get();
}
Returns the time zone used by this application. This is a simple wrapper of PHP function date_default_timezone_get().
public CUrlManager getUrlManager()
| ||
{return} | CUrlManager | the URL manager component |
public function getUrlManager()
{
return $this->getComponent('urlManager');
}
public void handleError(integer $code, string $message, string $file, integer $line)
| ||
$code | integer | the level of the error raised |
$message | string | the error message |
$file | string | the filename that the error was raised in |
$line | integer | the line number the error was raised at |
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
{
$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);
}
$this->end(1);
}
}
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 onError event.
If the error is not handled by any event handler, it will call
errorHandler to process the error.
The application will be terminated by this method.
public void handleException(Exception $exception)
| ||
$exception | Exception | exception that is not caught |
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.=' REQUEST_URI='.$_SERVER['REQUEST_URI'];
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);
}
$this->end(1);
}
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 onException event.
If the exception is not handled by any event handler, it will call
errorHandler to process the exception.
The application will be terminated by this method.
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());
}
Initializes the class autoloader and error handlers.
protected void loadGlobalState()
|
protected function loadGlobalState()
{
$persister=$this->getStatePersister();
if(($this->_globalState=$persister->load())===null)
$this->_globalState=array();
$this->_stateChanged=false;
$this->attachEventHandler('onEndRequest',array($this,'saveGlobalState'));
}
Loads the global state data from persistent storage.
public void onBeginRequest(CEvent $event)
| ||
$event | CEvent | the event parameter |
public function onBeginRequest($event)
{
$this->raiseEvent('onBeginRequest',$event);
}
Raised right BEFORE the application processes the request.
public void onEndRequest(CEvent $event)
| ||
$event | CEvent | the event parameter |
public function onEndRequest($event)
{
if(!$this->_ended)
{
$this->_ended=true;
$this->raiseEvent('onEndRequest',$event);
}
}
Raised right AFTER the application processes the request.
public void onError(CErrorEvent $event)
| ||
$event | CErrorEvent | event parameter |
public function onError($event)
{
$this->raiseEvent('onError',$event);
}
Raised when a PHP execution error occurs.
An event handler can set the handled
property of the event parameter to be true to indicate no further error
handling is needed. Otherwise, the errorHandler
application component will continue processing the error.
public void onException(CExceptionEvent $event)
| ||
$event | CExceptionEvent | event parameter |
public function onException($event)
{
$this->raiseEvent('onException',$event);
}
Raised when an uncaught PHP exception occurs.
An event handler can set the handled
property of the event parameter to be true to indicate no further error
handling is needed. Otherwise, the errorHandler
application component will continue processing the error.
abstract public void processRequest()
|
Processes the request. This is the place where the actual request processing work is done. Derived classes should override this method.
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',
),
);
$this->setComponents($components);
}
Registers the core application 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));
}
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.
protected void saveGlobalState()
|
protected function saveGlobalState()
{
if($this->_stateChanged)
{
$persister=$this->getStatePersister();
$this->_stateChanged=false;
$persister->save($this->_globalState);
}
}
Saves the global state data into persistent storage.
public void setBasePath(string $path)
| ||
$path | string | the root directory of the application. |
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)));
}
Sets the root directory of the application. This method can only be invoked at the begin of the constructor.
public void setExtensionPath(string $path)
| ||
$path | string | the directory that contains all third-party extensions. |
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 | the name of the value to be saved |
$value | mixed | the global value to be saved. It must be serializable. |
$defaultValue | mixed | the default value. If the named global value is the same as this value, it will be cleared from the current storage. |
public function setGlobalState($key,$value,$defaultValue=null)
{
if($this->_globalState===null)
$this->loadGlobalState();
$this->_stateChanged=true;
if($value===$defaultValue)
unset($this->_globalState[$key]);
else
$this->_globalState[$key]=$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.
public void setId(string $id)
| ||
$id | string | a unique identifier for the application. |
public function setId($id)
{
$this->_id=$id;
}
public void setLanguage(string $language)
| ||
$language | string | the user language (e.g. 'en_US', 'zh_CN'). If it is null, the sourceLanguage will be used. |
public function setLanguage($language)
{
$this->_language=$language;
}
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 source language.
Unless your application needs to support multiple languages, you should always
set this language to null to maximize the application's performance.
public void setRuntimePath(string $path)
| ||
$path | string | the directory that stores runtime files. |
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 | the time zone used by this application. |
public function setTimeZone($value)
{
date_default_timezone_set($value);
}
Sets the time zone used by this application. This is a simple wrapper of PHP function date_default_timezone_set().
Signup or Login in order to comment.