Application API

From The Smartest Wiki
Jump to: navigation, search

Smartest has an API that allows you to build your own applications and use Smartest's libraries as a framework. Smartest's own internal architecture is built on this same framework.

Smartest applications are essentially Quince modules which gain additional Smartest-specific functionality by extending SmartestUserApplication instead of QuinceBase.

API functions from Quince

protected void $this->redirect(string $destination) - redirects the user via a HTTP Location header, meaning a new request to the URL in that header.

protected void $this->forward(string $module_shortname, string $action_name) - internally updates the action name, meaning the user can be forwarded from one action to another without a further HTTP request.

protected object QuinceRequest $this->getRequest() - Returns the QuinceRequest object that contains information about the current request.

protected void $this->setContentType(string $response_mime_type) - sets the mime type sent to the user agent by Quince (default 'text/html').

protected void $this->setCharset(string $charset) - sets the charset sent to the user agent by Quince (default 'utf-8').

protected void $this->sendContentTypeHeader([$string $mime_type, [$string charset]]) - sends a content type header using the values supplied in $mime_type and $charset or the Quince defaults if none are supplied.

API functions for all applications

protected $string $this->getApplicationDirectory() - returns the main directory where the application (or in Quince terms, module) is located, which is usually of the form ROOT_DIR/Applications/APPLICATION_NAME/ or ROOT_DIR/System/Applications/APPLICATION_NAME/

protected $string $this->getConfigurationDirectory() - returns the directory where the application (or in Quince terms, module) stores configuration files, which is usually of the form ROOT_DIR/Applications/APPLICATION_NAME/Configuration/ or ROOT_DIR/System/Applications/APPLICATION_NAME/Configuration/

protected $string $this->getPresentationDirectory() - returns the directory where the application (or in Quince terms, module) stores template files, which is usually of the form ROOT_DIR/Applications/APPLICATION_NAME/Presentation/ or ROOT_DIR/System/Applications/APPLICATION_NAME/Presentation/

protected $string $this->getRequestParameter(string $parameter_name, [mixed $default_value]); returns the value of a request parameter. Parameters here may come from any of three sources, in increasing order of priority: URL variables, POST variables, GET variables.

protected void $this->setRequestParameter(string $parameter_name, mixed $parameter_value) - allows you to manually override any request variables, which is useful when $this->forward() is being used (see above)

protected boolean $this->requestParameterIsSet(string $parameter_name) - returns true if a value for the variable has been set, otherwise false.

protected object SmartestEngine (or desendants) $this->getPresentationLayer() - returns the Smarty object that will be used for the current request.

protected object SmartestUserAgentHelper $this->getUserAgent() - returns the user agent object, an instance of SmartestUserAgentHelper

protected void $this->send(mixed $value, string $template_variable_name) - assigns a value to the template layer. Note the order of arguments, value first.

protected boolean $this->sent(string $template_variable_name) - checks whether a template variable with the name provided has been assigned or not.

protected object SmartestSite $this->getSite() - returns the current active site, for null if none is active.

protected mixed $this->getApplicationPreference(string $preference_name, [mixed $default_value]) - returns the value of the stated application-specific preference. If no value is found and $default value is sent, this value will be returned, meaning that new preferences that don't yet have a value can work "out of the box"

protected boolean $this->setApplicationPreference(string $preference_name, mixed $value) - sets the named application-specific preference with the supplied value.

protected mixed $this->getGlobalPreference(string $preference_name, [mixed $default_value]) - returns the value of the stated global preference. If no value is found and $default value is sent, this value will be returned, meaning that new preferences that don't yet have a value can work "out of the box"

protected boolean $this->setGlobalPreference(string $preference_name, [mixed $value]) - sets the named global preference with the supplied value.

API functions for user applications

See User application API

API functions for system applications

See System application API