Craft

Type
Class
Namespace
Craft
Inherits
Craft\Craft » Yii
Since
1.0

Craft is helper class serving common Craft and Yii framework functionality.

It encapsulates {@link \Yii} and ultimately {@link \YiiBase}, which provides the actual implementation.

It also defines the global craft() method, which is a wrapper for the Craft::app() singleton.

See also http://craftcms.com

View source

Public Methods

MethodDescription
dd()Displays a variable and ends the request. (“Dump and die”)
disableMaintenanceMode()Disables Maintenance Mode.
dump()Displays a variable.
enableMaintenanceMode()Enables Maintenance Mode.
getBuild()Returns the installed Craft build.
getInfo()Returns the info model, or just a particular attribute.
getReleaseDate()Returns the installed Craft release date.
getSiteName()Returns the site name.
getSiteUid()Returns the site UID.
getSiteUrl()Returns the site URL.
getTimeZone()Returns the system time zone.
getTrack()Returns the Craft track.
getVersion()Returns the installed Craft version.
getYiiVersion()Returns the Yii framework version.
hasPackage()Returns whether a package is included in this Craft build.
import()Takes a path alias and will import any files/folders that it contains.
isInMaintenanceMode()Returns whether the system is in maintenance mode or not.
isInstalled()Determines if Craft is installed by checking if the info table exists in the database.
isSystemOn()Returns whether the system is on.
log()Logs a message. Messages logged by this method may be retrieved via {@link Logger::getLogs} and may be recorded in different media, such as file, email, database, using {@link LogRouter}.
saveInfo()Updates the info row with new information.
setIsInstalled()Tells Craft that it's installed now.
t()Translates a given message into the specified language. If the config setting 'translationDebugOutput' is set, the the output will be wrapped in a pair of '@' to help diagnose any missing translations.

dd()

Displays a variable and ends the request. (“Dump and die”)

View source

Arguments

  • $target (mixed) – The variable to be dumped.
  • $depth (integer) – The maximum depth that the dumper should go into the variable. Defaults to 10.
  • $highlight (boolean) – Whether the result should be syntax-highlighted. Defaults to true.

Returns

null

Signature

public static null dd ( $target, $depth = 10, $highlight = true )

disableMaintenanceMode()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::disableMaintenanceMode() craft()->disableMaintenanceMode()} instead.

Disables Maintenance Mode.

View source

Returns

boolean

Signature

public static boolean disableMaintenanceMode ( )

dump()

Displays a variable.

View source

Arguments

  • $target (mixed) – The variable to be dumped.
  • $depth (integer) – The maximum depth that the dumper should go into the variable. Defaults to 10.
  • $highlight (boolean) – Whether the result should be syntax-highlighted. Defaults to true.

Returns

null

Signature

public static null dump ( $target, $depth = 10, $highlight = true )

enableMaintenanceMode()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::enableMaintenanceMode() craft()->enableMaintenanceMode()} instead.

Enables Maintenance Mode.

View source

Returns

boolean

Signature

public static boolean enableMaintenanceMode ( )

getBuild()

DEPRECATED

Deprecated Deprecated in 1.3.

Returns the installed Craft build.

View source

Returns

string

Signature

public static string getBuild ( )

getInfo()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getInfo() craft()->getInfo()} instead.

Returns the info model, or just a particular attribute.

View source

Arguments

  • $attribute (string, null) – The attribute to return information about.

Returns

mixed

Throws

Signature

public static mixed getInfo ( $attribute = null )

getReleaseDate()

DEPRECATED

Deprecated Deprecated in 1.3.

Returns the installed Craft release date.

View source

Returns

string

Signature

public static string getReleaseDate ( )

getSiteName()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getSiteName() craft()->getSiteName()} instead.

Returns the site name.

View source

Returns

string

Signature

public static string getSiteName ( )

getSiteUid()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getSiteUid() craft()->getSiteUid()} instead.

Returns the site UID.

View source

Returns

string

Signature

public static string getSiteUid ( )

getSiteUrl()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getSiteUrl() craft()->getSiteUrl()} instead.

Returns the site URL.

View source

Arguments

  • $protocol (string, null) – The protocol to use (http or https). If none is specified, it will default to whatever is in the Site URL setting.

Returns

string

Signature

public static string getSiteUrl ( $protocol = null )

getTimeZone()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getTimeZone() craft()->getTimeZone()} instead.

Returns the system time zone.

View source

Returns

string

Signature

public static string getTimeZone ( )

getTrack()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getTrack() craft()->getTrack()} instead.

Returns the Craft track.

View source

Returns

string

Signature

public static string getTrack ( )

getVersion()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getVersion() craft()->getVersion()} instead.

Returns the installed Craft version.

View source

Returns

string

Signature

public static string getVersion ( )

getYiiVersion()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::getYiiVersion() craft()->getYiiVersion()} instead.

Returns the Yii framework version.

View source

Returns

mixed

Signature

public static mixed getYiiVersion ( )

hasPackage()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::hasPackage() craft()->hasPackage()} instead.

Returns whether a package is included in this Craft build.

View source

Arguments

  • $packageName (string) – The name of the package to search for.

Returns

boolean

Signature

public static boolean hasPackage ( $packageName )

import()

Takes a path alias and will import any files/folders that it contains.

View source

Arguments

  • $alias (string) – The path alias to import.
  • $forceInclude (boolean) – If set to true, Craft will require_once the file. Defaults to false.

Returns

string, null

Throws

Signature

public static string, null import ( $alias, $forceInclude = false )

isInMaintenanceMode()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::isInMaintenanceMode() craft()->isInMaintenanceMode()} instead.

Returns whether the system is in maintenance mode or not.

View source

Returns

boolean

Signature

public static boolean isInMaintenanceMode ( )

isInstalled()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::isInstalled() craft()->isInstalled()} instead.

Determines if Craft is installed by checking if the info table exists in the database.

View source

Returns

boolean

Signature

public static boolean isInstalled ( )

isSystemOn()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::isSystemOn() craft()->isSystemOn()} instead.

Returns whether the system is on.

View source

Returns

boolean

Signature

public static boolean isSystemOn ( )

log()

Logs a message. Messages logged by this method may be retrieved via {@link Logger::getLogs} and may be recorded in different media, such as file, email, database, using {@link LogRouter}.

View source

Arguments

  • $msg (string) – The message to be logged.
  • $level (string) – The level of the message (e.g. LogLevel::Trace', LogLevel::Info, LogLevel::Warning or LogLevel::Error). Defaults to LogLevel::Info.
  • $force (boolean) – Whether to force the message to be logged regardless of the level or category.
  • $category (string) – The category of the message (e.g. 'application'). It is case-insensitive.
  • $plugin (string) – The plugin handle that made the log call. If null, will be set to 'craft'. Use for determining which log file to write to.

Returns

null

Signature

public static null log ( $msg, $level = \Craft\LogLevel::Info, $force = false, $category = 'application', $plugin = null )

saveInfo()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::saveInfo() craft()->saveInfo()} instead.

Updates the info row with new information.

View source

Arguments

Returns

boolean

Signature

public static boolean saveInfo ( Craft\InfoModel $info )

setIsInstalled()

DEPRECATED

Deprecated Deprecated in 1.3. Use {@link AppBehavior::setIsInstalled() craft()->setIsInstalled()} instead.

Tells Craft that it's installed now.

View source

Signature

public static void setIsInstalled ( )

t()

Translates a given message into the specified language. If the config setting 'translationDebugOutput' is set, the the output will be wrapped in a pair of '@' to help diagnose any missing translations.

View source

Arguments

  • $message (string) – The original source message.
  • $variables (array) – An associative array of key => value pairs to be applied to the message using strtr.
  • $source (string, null) – Defines which message source application component to use. Defaults to null, meaning use 'coreMessages' for messages belonging to the 'yii' category and using 'messages' for messages belonging to Craft.
  • $language (string, null) – The target language. If set to null (default), craft()->getLanguage() will be used.
  • $category (string) – The message category. Please use only word letters. Note, category 'craft' is reserved for Craft and 'yii' is reserved for the Yii framework.

Returns

string, null – The translated message, or null if the source key could not be found.

Signature

public static string, null t ( $message, $variables = [], $source = null, $language = null, $category = 'craft' )

Constants

ConstantDescription
Client
Personal
Pro