Methods
-
accountName
Returns account name saved in Installer settings.
-
appExists
Verifies whether application with specified id exists.
-
getApp
Returns current app's id.
-
getAppInfo
Returns information about specified app from its file
wa-apps/[app_id]/lib/config/app.php
. -
getAppPath
Returns path to app’s source files directory.
-
getAppPathRelativeToFrameworkRoot
Returns path to the current app’s directory relative to the framework’s root path.
-
getAppStaticUrl
Returns the URL of specified app's source files directory.
-
getAppUrl
Returns the relative URL of specified app's main backend page.
-
getConfig
Returns an instance of the configuration management class.
-
getConfigPath
Returns the path to framework's directory used for storing custom configuration files.
-
getDataPath
Returns the path to framework's directory used for storing user data files.
-
getDataUrl
Returns the URL of the directory used for storing user data files for the specified app.
-
getEnv
Determines the type of user request environment:
backend
orfrontend
. -
getInstance
Returns an instance of the main system class.
-
getLocale
Returns current user's locale.
-
getPlugin
Returns app plugin’s class instance.
-
getResponse
Returns an instance of the class used for generating response to user requests.
-
getRootUrl
Returns the root URL of the framework installation directory.
-
getRouteUrl
Returns URL corresponding to the specified combination of app's module and action.
-
getSetting
Returns a setting value for specified app.
-
getStorage
Returns an instance of the class used for managing user sessions.
-
getTempPath
Returns path to directory used for storing temporary files of an app.
-
getUrl
Returns the main URL of the current frontend or backend section.
-
getUser
Returns an instance of the class used for accessing user-related information.
-
getVersion
Returns version number for specified app.
-
getView
Returns an instance of the class used for generation of web pages.
-
isSingleAppMode
Returns the single-app mode status.
-
setLocale
Sets the specified locale for framework's dynamic configuration.
-
getWidget
Returns a widget class instance.
public function accountName()
Returns account name saved in Installer settings.
Example
wa()->accountName()
Result
Webasyst
public function appExists ($app_id)
Verifies whether application with specified id exists.
Parameters
-
$app_id
App's id.
Example
wa()->appExists('someapp')
Result
false //there is no installed app with id 'someapp'
public static function getApp()
Returns current app's id.
Example
wa()->getApp()
Result
myapp //method getApp was called in the source code of an app with id 'myapp'; therefore this app is considered as active
public function getAppInfo ($app_id = null)
Returns information about specified app from its file wa-apps/[app_id]/lib/config/app.php
.
Parameters
-
$app_id
Optional app id. If not specified, then current app's id is used by default.
Example
wa()->getAppInfo('blog')
Result
Array ( [name] => Blog [icon] => Array ( [16] => wa-apps/blog/img/blog16.png [24] => wa-apps/blog/img/blog24.png [48] => wa-apps/blog/img/blog.png [96] => wa-apps/blog/img/blog96.png ) [rights] => 1 [frontend] => 1 [auth] => 1 [themes] => 1 [plugins] => 1 [pages] => 1 [mobile] => 1 [version] => 1.2.0 [critical] => 1.0.0 [vendor] => webasyst [csrf] => 1 [build] => 27730 [id] => blog [img] => wa-apps/blog/img/blog.png )
public function getAppPath ($path = null, $app_id = null)
Returns path to app's source files directory.
Parameters
-
$path
Optional path to a subdirectory inside the main directory with app's source files.
-
$app_id
Optional app id. If not specified, then current app's id is used by default.
Example
wa()->getAppPath('templates', 'blog')
Result
/var/www/wa-apps/blog/templates
public function getAppPathRelativeToFrameworkRoot ($app = null)
Returns path to the current app’s directory relative to the framework’s root path.
Parameters
-
$app
Optional app id. If not specified, then current app's id is used by default.
Example
wa()->getAppPathRelativeToFrameworkRoot('blog');
Result
wa-apps/blog/
public function getAppStaticUrl ($app = null, $absolute = false)
Returns the URL of specified app's source files directory.
Parameters
-
$app
Optional app id. If not specified, then current app's id is used by default.
-
$absolute
Flag requiring to return the absolute URL instead of the relative (default) one.
Example
wa()->getAppStaticUrl('blog', true)
Result
http://yourdomain.com/wa-apps/blog/
public function getAppUrl ($app = null, $script = false)
Returns the relative URL of specified app's main backend page.
Parameters
-
$app
Optional app id. If not specified, then current app's id is used by default.
-
$script
Flag requiring to return a URL containing
index.php/
in cases when modulemod_rewrite
(or similar mechanism) for generating human-readable URLs is not installed.
Example
wa()->getAppUrl('blog')
Result
/webasyst/blog/
public function getConfig()
Returns an instance of the configuration management class (waSystemConfig
or waAppConfig
).
Example
wa()->getConfig()->getRootPath()
Result
/var/www
public function getConfigPath ($app_id = null)
Returns the path to framework's directory used for storing custom configuration files.
Parameters
-
$app_id
Id of the app for which the path to configuration file directory must be returned. If not specified, the method returns the path to the common configuration file directory.
Example
wa()->getConfigPath('blog')
Result
/var/www/wa-config/apps/blog
public function getDataPath ($path = null, $public = false, $app_id = null, $create = true)
Returns the path to framework's directory used for storing user data files.
Parameters
-
$path
Path to directory. If not specified, the method returns path to the main directory with user data files.
-
$public
Flag requiring to return path to the subdirectory used for storing files which are publicly accessible without authorization, by direct link. If
false
is specified (default value), then the method returns the path to the subdirectory used for storing files which are accessible only upon authorization in the backend. -
$app_id
Optional app id. If not specified, then current app's id is used by default.
-
$create
Flag requiring to create a new directory directory at the specified path if it is missing. New directories are created by default if
false
is not specified.
Example
wa()->getDataPath('themes', true, 'blog')
Result
/var/www/wa-data/public/blog/themes
public function getDataUrl ($path = null, $public = false, $app_id = null, $absolute = false)
Returns the URL of the directory used for storing user data files for the specified app.
Parameters
-
$path
Path to directory. If not specified, the method returns URL of the main directory with user data files.
-
$public
Flag requiring to return URL of the subdirectory used for storing files which are publicly accessible without authorization, by direct link. If
false
is specified (default value), then the method returns URL of the subdirectory used for storing files which are accessible only upon authorization in the backend. -
$app_id
Optional app id. If not specified, then current app's id is used by default.
-
$absolute
Flag requiring to return the absolute URL instead of the relative (default) one.
Example
wa()->getDataUrl('themes', true, 'blog', true)
Result
http://yourdomain.com/wa-data/public/blog/themes
public function getEnv()
Determines the type of user request environment: backend
or frontend
.
Example
wa()->getEnv()
Result
backend //method getEnv was called in backend action or controller
public static function getInstance ($name = null, waSystemConfig $config = null, $set_current = false)
Returns an instance of the main system class. Short method of obtaining the same result is to use function wa()
.
Parameters
-
$name
Id of the app whose configuration must be temporarily initialized instead of current app's configuration.
Example
waSystem::getInstance()->accountName() //full syntax wa()->accountName() //short syntax
Example
waSystem::getInstance()->getConfig()->getApplication() //method will return current app's id waSystem::getInstance('blog')->getConfig()->getApplication() //method will return id of the specified app, i.e. 'blog'
public function getLocale()
Returns current user's locale.
Example
wa()->getLocale()
Result
en_US
public function getPlugin($plugin_id, $set_active = false)
Returns app plugin’s class instance.
Parameters
-
$plugin_id
Current app’s plugin ID.
-
$set_active
Flag requiring to set the plugin as active.
Example
$plugin_instance = wa()->getPlugin('myplugin');
public function getResponse()
Returns an instance of the class used for generating response to user requests. (waResponse
).
Example
wa()->getResponse()->redirect('http://otherdomain.com')
public function getRootUrl ($absolute = false, $script = false)
Returns the root URL of the framework installation directory.
Parameters
-
$absolute
Flag requiring to return the absolute URL instead of the relative (default) one.
-
$script
Flag requiring to return a URL containing
index.php/
in cases when modulemod_rewrite
(or similar mechanism) for generating human-readable URLs is not installed.
Example
wa()->getRootUrl(true)
Result
http://yourdomain.com/
public function getRouteUrl ($path, $params = array(), $absolute = false, $domain = null, $route = null)
Returns URL corresponding to the specified combination of app's module and action based on the contents of configuration file routing.php
of that app.
Parameters
-
$path
App, module, and action IDs separated by slash (/).
-
$params
Associative array of the following optional parameters:
'domain'
: domain name specified for one of the websites set up in the framework'module'
: module id'action'
: action id- dynamic URL parameters described in the app's configuration file
routing.php
for the specified module and action; for example,category_url
is such a dynamic parameter in the following routing conifiguration entry:'category/<category_url>/' => 'frontend/category',
If module and action are specified in the array of optional parameters, then they may be omitted in the first (string) parameter of the method.
-
$absolute
Flag requiring to return an absolute URL instead of a relative one.
-
$domain
Address of site to generate a URL for.
-
$route
Address of a routing rule to generate a URL for.
Example
wa()->getRouteUrl('shop/frontend/cart'); //return URL corresponding to the routing rule specified in file routing.php of an app with id 'shop'
Result
/cart/ — settlement for an app with id 'shop' is set up for the domain root directory /shop/cart/ — settlement for an app with id 'shop' is set up for subdirectory 'shop/'
Example
$params = array( 'domain' => 'yourdomain.com', //specify the URL of one of multiple websites set up in your backend to take its routing rules into account while generating the URL 'tag' => 'sony', //dynamic URL parameter ); wa()->getRouteUrl('shop/frontend/tag', $params, true);
Result
http://yourdomain.com/tag/sony/
Example
$params = array( 'domain' => 'yourdomain.com', 'module' => 'frontend', 'action' => 'tag', 'tag' => 'sony', ); wa()->getRouteUrl('shop', $params, true); //module and action are specified in the array of optional parameters; therefore, only app id is necessary in the first parameter
Result
http://yourdomain.com/tag/sony/
public static function getSetting ($name, $default = '', $app_id = null)
Returns a setting value for specified app.
Parameters
-
$name
Settings field string id.
-
$default
Default value, which is returned if the requested settings field does not contain a value.
-
$app_id
Optional app id. If not specified, then current app's id is used by default.
Example
wa()->getSetting('currency', 'USD', 'shop')
Result
EUR //Euro is selected as the default currency in online store's settings
public function getStorage()
Returns an instance of the class used for managing user sessions. (waSessionStorage
).
Example
wa()->getStorage()->getAll()
public function getTempPath ($path = null, $app_id = null)
Returns path to directory used for storing temporary files of an app.
Parameters
-
$path
Optional path to a subdirectory inside the main directory used for storing temporary files.
-
$app_id
Optional app id. If not specified, then current app's id is used by default.
Example
wa()->getTempPath(null, 'blog')
Result
/var/www/wa-cache/temp/blog
public function getUrl ($absolute = false)
Returns the main URL of the current frontend or backend section. If a request is sent to frontend, then the method return the frmaework's root frontend URL. If a request is sent to backend, then the method returns the main backend URL of the app responsible for processing the request.
Parameters
-
$absolute
Flag requiring to return the absolute URL instead of the relative (default) one.
Example
wa()->getUrl(true)
Result
http://yourdomain/webasyst/myapp/ //method getUrl was called in the source code of an app with id 'myapp'
public function getUser()
Returns an instance of the class used for accessing user-related information. (waAuthUser
, waUser
, or waContact
).
Example
wa()->getUser()->getId()
public function getVersion ($app_id = null)
Returns version number for specified app.
Parameters
-
$app_id
Optional app id. If not specified, then current app's id is used by default.
Example
wa()->getVersion('photos')
Result
1.1.0.27730
public function getView ($options = array())
Returns an instance of the class used for generation of web pages (template engine). By default, class waSmarty3View
is used, which implements the functionality of Smarty template engine. Read more about use of alternative template engines »
Parameters
-
$options
Array of parameters for the initialization of a template engine class instance.
Example
wa()->getView()->assign('myvar', $value) $this->view->assign('myvar', $value) //an instance of the currently used template engine class is accessible via the 'view' variable in the instances of classeswaViewAction
andwaViewActions
.
public function isSingleAppMode ()
Returns the single-app mode status.
Example
$is_single_app_mode = wa()->isSingleAppMode();
public function setLocale ($locale)
Sets the specified locale for framework's dynamic configuration.
Parameters
-
$locale
Id of the locale which must be set for the framework's current dynamic configuration.
Example
wa()->setLocale('en_US')
public function getWidget($widget_id, array $options = [])
Returns a widget class instance.
Parameters
-
$widget_id
Widget’s database record ID.
-
$options
Additional widget initialization parameters.
Example
$widget_instance = wa()->getWidget(1, [ 'contact_id' => 42, ]);