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 (opens new window)

# Public Methods

Method Description
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 (opens new window)

Arguments

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

Returns

null (opens new window)

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 (opens new window)

Returns

boolean (opens new window)

Signature

public static boolean disableMaintenanceMode ( )

# dump()

Displays a variable.

View source (opens new window)

Arguments

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

Returns

null (opens new window)

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 (opens new window)

Returns

boolean (opens new window)

Signature

public static boolean enableMaintenanceMode ( )

# getBuild()

DEPRECATED

Deprecated Deprecated in 1.3.

Returns the installed Craft build.

View source (opens new window)

Returns

string (opens new window)

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 (opens new window)

Arguments

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 (opens new window)

Returns

string (opens new window)

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 (opens new window)

Returns

string (opens new window)

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 (opens new window)

Returns

string (opens new window)

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 (opens new window)

Arguments

Returns

string (opens new window)

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 (opens new window)

Returns

string (opens new window)

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 (opens new window)

Returns

string (opens new window)

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 (opens new window)

Returns

string (opens new window)

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 (opens new window)

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 (opens new window)

Arguments

Returns

boolean (opens new window)

Signature

public static boolean hasPackage ( $packageName )

# import()

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

View source (opens new window)

Arguments

Returns

string (opens new window), null (opens new window)

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 (opens new window)

Returns

boolean (opens new window)

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 (opens new window)

Returns

boolean (opens new window)

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 (opens new window)

Returns

boolean (opens new window)

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 (opens new window)

Arguments

  • $msg (string (opens new window)) – The message to be logged.
  • $level (string (opens new window)) – The level of the message (e.g. LogLevel::Trace', LogLevel::Info, LogLevel::Warning or LogLevel::Error). Defaults to LogLevel::Info.
  • $force (boolean (opens new window)) – Whether to force the message to be logged regardless of the level or category.
  • $category (string (opens new window)) – The category of the message (e.g. 'application'). It is case-insensitive.
  • $plugin (string (opens new window)) – 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 (opens new window)

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 (opens new window)

Arguments

Returns

boolean (opens new window)

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 (opens new window)

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 (opens new window)

Arguments

Returns

string (opens new window), null (opens new window) – 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

Constant Description
Client
Personal
Pro