system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

YiiBase

system
继承 class YiiBase
子类 Yii
可用自 1.0
版本 $Id$
YiiBase is a helper class serving common framework functionalities.

Do not use YiiBase directly. Instead, use its child class Yii where you can customize methods of YiiBase.

公共方法

隐藏继承的方法

方法描述被定义在
app() YiiBase
autoload() Class autoload loader. YiiBase
beginProfile() Marks the begin of a code block for profiling. YiiBase
createApplication() Creates an application of the specified class. YiiBase
createComponent() Creates an object and initializes it based on the given configuration. YiiBase
createConsoleApplication() Creates a console application instance. YiiBase
createWebApplication() Creates a Web application instance. YiiBase
endProfile() Marks the end of a code block for profiling. YiiBase
getFrameworkPath() YiiBase
getLogger() YiiBase
getPathOfAlias() Translates an alias into a file path. YiiBase
getVersion() YiiBase
import() Imports the definition of a class or a directory of class files. YiiBase
log() Logs a message. YiiBase
powered() YiiBase
registerAutoloader() Registers a new class autoloader. YiiBase
setApplication() Stores the application instance in the class static member. YiiBase
setPathOfAlias() Create a path alias. YiiBase
t() Translates a message to the specified language. YiiBase
trace() Writes a trace message. YiiBase

方法详情

app() 方法
public static CApplication app()
{return} CApplication the application singleton, null if the singleton has not been created yet.

autoload() 方法
public static boolean autoload(string $className)
$className string class name
{return} boolean whether the class has been loaded successfully

Class autoload loader. This method is provided to be invoked within an __autoload() magic method.

beginProfile() 方法
public static void beginProfile(string $token, string $category='application')
$token string token for the code block
$category string the category of this log message

Marks the begin of a code block for profiling. This has to be matched with a call to endProfile() with the same token. The begin- and end- calls must also be properly nested, e.g.,

Yii::beginProfile('block1');
Yii::beginProfile('block2');
Yii::endProfile('block2');
Yii::endProfile('block1');
The following sequence is not valid:
Yii::beginProfile('block1');
Yii::beginProfile('block2');
Yii::endProfile('block1');
Yii::endProfile('block2');

参见

createApplication() 方法 (自版本 v1.0.10 可用)
public static mixed createApplication(string $class, mixed $config=NULL)
$class string the application class name
$config mixed application configuration. This parameter will be passed as the parameter to the constructor of the application class.
{return} mixed the application instance

Creates an application of the specified class.

createComponent() 方法
public static mixed createComponent(mixed $config)
$config mixed the configuration. It can be either a string or an array.
{return} mixed the created object

Creates an object and initializes it based on the given configuration.

The specified configuration can be either a string or an array. If the former, the string is treated as the object type which can be either the class name or class path alias. If the latter, the 'class' element is treated as the object type, and the rest name-value pairs in the array are used to initialize the corresponding object properties.

Any additional parameters passed to this method will be passed to the constructor of the object being created.

NOTE: the array-typed configuration has been supported since version 1.0.1.

createConsoleApplication() 方法
public static void createConsoleApplication(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'.

Creates a console application instance.

createWebApplication() 方法
public static void createWebApplication(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'.

Creates a Web application instance.

endProfile() 方法
public static void endProfile(string $token, string $category='application')
$token string token for the code block
$category string the category of this log message

Marks the end of a code block for profiling. This has to be matched with a previous call to beginProfile() with the same token.

参见

getFrameworkPath() 方法
public static string getFrameworkPath()
{return} string the path of the framework

getLogger() 方法
public static CLogger getLogger()
{return} CLogger message logger

getPathOfAlias() 方法
public static mixed getPathOfAlias(string $alias)
$alias string alias (e.g. system.web.CController)
{return} mixed file path corresponding to the alias, false if the alias is invalid.

Translates an alias into a file path. Note, this method does not ensure the existence of the resulting file path. It only checks if the root alias is valid or not.

getVersion() 方法
public static string getVersion()
{return} string the version of Yii framework

import() 方法
public static string import(string $alias, boolean $forceInclude=false)
$alias string path alias to be imported
$forceInclude boolean whether to include the class file immediately. If false, the class file will be included only when the class is being used.
{return} string the class name or the directory that this alias refers to

Imports the definition of a class or a directory of class files.

Path aliases are used to refer to the class file or directory being imported. If importing a path alias ending with '.*', the alias is considered as a directory which will be added to the PHP include paths; Otherwise, the alias is translated to the path of a class file which is included when needed.

For example, importing 'system.web.*' will add the 'web' directory of the framework to the PHP include paths; while importing 'system.web.CController' will include the class file 'web/CController.php' when needed.

The same alias can be imported multiple times, but only the first time is effective.

log() 方法
public static void log(string $msg, string $level='info', string $category='application')
$msg string message to be logged
$level string level of the message (e.g. 'trace', 'warning', 'error'). It is case-insensitive.
$category string category of the message (e.g. 'system.web'). It is case-insensitive.

Logs a message. Messages logged by this method may be retrieved via CLogger::getLogs and may be recorded in different media, such as file, email, database, using CLogRouter.

powered() 方法
public static string powered()
{return} string a string that can be displayed on your Web page showing Powered-by-Yii information

registerAutoloader() 方法 (自版本 v1.0.10 可用)
public static void registerAutoloader(callback $callback)
$callback callback a valid PHP callback (function name or array($className,$methodName)).

Registers a new class autoloader. The new autoloader will be placed before autoload and after any other existing autoloaders.

setApplication() 方法
public static void setApplication(CApplication $app)
$app CApplication the application instance. If this is null, the existing application singleton will be removed.

Stores the application instance in the class static member. This method helps implement a singleton pattern for CApplication. Repeated invocation of this method or the CApplication constructor will cause the throw of an exception. To retrieve the application instance, use app().

setPathOfAlias() 方法
public static void setPathOfAlias(string $alias, string $path)
$alias string alias to the path
$path string the path corresponding to the alias. If this is null, the corresponding path alias will be removed.

Create a path alias. Note, this method neither checks the existence of the path nor normalizes the path.

t() 方法
public static string t(string $category, string $message, array $params=array ( ), string $source=NULL, string $language=NULL)
$category string message category. Please use only word letters. Note, category 'yii' is reserved for Yii framework core code use. See CPhpMessageSource for more interpretation about message category.
$message string the original message
$params array parameters to be applied to the message using strtr. Starting from version 1.0.2, the first parameter can be a number without key. And in this case, the method will call CChoiceFormat::format to choose an appropriate message translation.
$source string which message source application component to use. Defaults to null, meaning using 'coreMessages' for messages belonging to the 'yii' category and using 'messages' for the rest messages.
$language string the target language. If null (default), the application language will be used. This parameter has been available since version 1.0.3.
{return} string the translated message

Translates a message to the specified language. Starting from version 1.0.2, this method supports choice format (see CChoiceFormat), i.e., the message returned will be chosen from a few candidates according to the given number value. This feature is mainly used to solve plural format issue in case a message has different plural forms in some languages.

trace() 方法
public static void trace(string $msg, string $category='application')
$msg string message to be logged
$category string category of the message

Writes a trace message. This method will only log a message when the application is in debug mode.

参见