JApplication
Extends \JObjectBase class for a Joomla! application.
Acts as a Factory class for application specific objects and provides many supporting API functions. Derived clases should supply the route(), dispatch() and render() functions.
package |
Joomla.Platform |
---|---|
subpackage |
Application |
since |
11.1 |
Methods
__construct
Class constructor, overridden in descendant classes.
__construct(mixed $properties = null)
since |
11.1 |
---|
Arguments
- $properties
mixed
Either and associative array or another object to set the initial properties of the object.
__toString
Magic method to convert the object to a string gracefully.
__toString() : string
since |
11.1 |
---|---|
deprecated |
12.3 Classes should provide their own __toString() implementation. |
Response
string
The classname.
_createConfiguration
Create the configuration registry.
_createConfiguration(string $file) : object
since |
11.1 |
---|
Arguments
- $file
string
The path to the configuration file
Response
object
A JConfig object
_createSession
Create the user session.
_createSession(string $name) : \JSession
Old sessions are flushed based on the configuration value for the cookie lifetime. If an existing session, then the last access time is updated. If a new session, a session id is generated and a record is created in the #__sessions table.
since |
11.1 |
---|
Arguments
- $name
string
The sessions name.
Response
\JSession
JSession on success. May call exit() on database error.
checkSession
Checks the user session.
checkSession() : void
If the session record doesn't exist, initialise it. If session is new, create session variables
since |
11.1 |
---|
close
Exit the application.
close(integer $code) : void
since |
11.1 |
---|
Arguments
- $code
integer
Exit code
def
Sets a default value if not alreay assigned
def(string $property, mixed $default = null) : mixed
since |
11.1 |
---|
Arguments
- $property
string
The name of the property.- $default
mixed
The default value.
Response
mixed
dispatch
Dispatch the application.
dispatch(string $component = null) : void
Dispatching is the process of pulling the option from the request object and mapping them to a component. If the component does not exist, it handles determining a default component to dispatch.
since |
11.1 |
---|
Arguments
- $component
string
The component to dispatch.
enqueueMessage
Enqueue a system message.
enqueueMessage(string $msg, string $type = 'message') : void
since |
11.1 |
---|
Arguments
- $msg
string
The message to enqueue.- $type
string
The message type. Default is message.
get
Returns a property of the object or the default value if the property is not set.
get(string $property, mixed $default = null) : mixed
since |
11.1 |
---|---|
see | \JObject::getProperties() |
Arguments
- $property
string
The name of the property.- $default
mixed
The default value.
Response
mixed
The value of the property.
getCfg
Gets a configuration value.
getCfg(string $varname, string $default = null) : mixed
An example is in application/japplication-getcfg.php Getting a configuration
since |
11.1 |
---|
Arguments
- $varname
string
The name of the value to get.- $default
string
Default value to return
Response
mixed
The user state.
getClientId
Gets the client id of the current running application.
getClientId() : integer
since |
11.1 |
---|
Response
integer
A client identifier.
getError
Get the most recent error message.
getError(integer $i = null, boolean $toString = true) : string
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Arguments
- $i
integer
Option error index.- $toString
boolean
Indicates if JError objects should return their error message.
Response
string
Error message
getErrors
Return all errors, if any.
getErrors() : array
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Response
array
Array of error messages or JErrors.
getHash
Provides a secure hash based on a seed
getHash(string $seed) : string
since |
11.1 |
---|
Arguments
- $seed
string
Seed string.
Response
string
A secure hash
getInstance
Returns the global JApplication object, only creating it if it doesn't already exist.
getInstance(mixed $client, array $config = array(), string $prefix = 'J') : \JApplication
since |
11.1 |
---|
Arguments
- $client
mixed
A client identifier or name.- $config
array
An optional associative array of configuration settings.- $prefix
string
A prefix for class names
Response
\JApplication
A JApplication object.
getMenu
Returns the application JPathway object.
getMenu(string $name = null, array $options = array()) : \JMenu
since |
11.1 |
---|
Arguments
- $name
string
The name of the application/client.- $options
array
An optional associative array of configuration settings.
Response
\JMenu
JMenu object.
getMessageQueue
Get the system message queue.
getMessageQueue() : array
since |
11.1 |
---|
Response
array
The system message queue.
getName
Method to get the application name.
getName() : string
The dispatcher name is by default parsed using the classname, or it can be set by passing a $config['name'] in the class constructor.
since |
11.1 |
---|
Response
string
The name of the dispatcher.
getPathway
Returns the application JPathway object.
getPathway(string $name = null, array $options = array()) : \JPathway
since |
11.1 |
---|
Arguments
- $name
string
The name of the application.- $options
array
An optional associative array of configuration settings.
Response
\JPathway
A JPathway object
getProperties
Returns an associative array of object properties.
getProperties(boolean $public = true) : array
since |
11.1 |
---|---|
see | \JObject::get() |
Arguments
- $public
boolean
If true, returns only the public properties.
Response
array
getRouter
Returns the application JRouter object.
getRouter(string $name = null, array $options = array()) : \JRouter
since |
11.1 |
---|
Arguments
- $name
string
The name of the application.- $options
array
An optional associative array of configuration settings.
Response
\JRouter
A JRouter object
getTemplate
Gets the name of the current template.
getTemplate(array $params = false) : string
since |
11.1 |
---|
Arguments
- $params
array
An optional associative array of configuration settings
Response
string
System is the fallback.
getUserState
Gets a user state.
getUserState(string $key, mixed $default = null) : mixed
since |
11.1 |
---|
Arguments
- $key
string
The path of the state.- $default
mixed
Optional default value, returned if the internal value is null.
Response
mixed
The user state or null.
getUserStateFromRequest
Gets the value of a user state variable.
getUserStateFromRequest(string $key, string $request, string $default = null, string $type = 'none') : \The
since |
11.1 |
---|
Arguments
- $key
string
The key of the user state variable.- $request
string
The name of the variable passed in a request.- $default
string
The default value for the variable if not found. Optional.- $type
string
Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.
Response
\The
request user state.
initialise
Initialise the application.
initialise(array $options = array()) : void
since |
11.1 |
---|
Arguments
- $options
array
An optional associative array of configuration settings.
isAdmin
Is admin interface?
isAdmin() : boolean
since |
11.1 |
---|
Response
boolean
True if this application is administrator.
isSite
Is site interface?
isSite() : boolean
since |
11.1 |
---|
Response
boolean
True if this application is site.
isWinOS
Method to determine if the host OS is Windows
isWinOS() : boolean
since |
11.1 |
---|
Response
boolean
True if Windows OS
login
Login authentication function.
login(array $credentials, array $options = array()) : boolean
Username and encoded password are passed the onUserLogin event which is responsible for the user validation. A successful validation updates the current session record with the user's details.
Username and encoded password are sent as credentials (along with other possibilities) to each observer (authentication plugin) for user validation. Successful validation will update the current session with the user details.
since |
11.1 |
---|
Arguments
- $credentials
array
Array('username' => string, 'password' => string)- $options
array
Array('remember' => boolean)
Response
boolean
True on success.
logout
Logout authentication function.
logout(integer $userid = null, array $options = array()) : boolean
Passed the current user information to the onUserLogout event and reverts the current session record back to 'anonymous' parameters. If any of the authentication plugins did not successfully complete the logout routine then the whole method fails. Any errors raised should be done in the plugin as this provides the ability to give much more information about why the routine may have failed.
since |
11.1 |
---|
Arguments
- $userid
integer
The user to load - Can be an integer or string - If string, it is converted to ID automatically- $options
array
Array('clientid' => array of client id's)
Response
boolean
True on success
redirect
Redirect to another URL.
redirect(string $url, string $msg = '', string $msgType = 'message', boolean $moved = false) : void
Optionally enqueues a message in the system message queue (which will be displayed the next time a page is loaded) using the enqueueMessage method. If the headers have not been sent the redirect will be accomplished using a "301 Moved Permanently" code in the header pointing to the new location. If the headers have already been sent this will be accomplished using a JavaScript statement.
since |
11.1 |
---|---|
see | \JApplication::enqueueMessage() |
Arguments
- $url
string
The URL to redirect to. Can only be http/https URL- $msg
string
An optional message to display on redirect.- $msgType
string
An optional message type. Defaults to message.- $moved
boolean
True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
registerEvent
Registers a handler to a particular event group.
registerEvent(string $event, mixed $handler) : void
since |
11.1 |
---|
Arguments
- $event
string
The event name.- $handler
mixed
The handler, a function or an instance of a event object.
render
Render the application.
render() : void
Rendering is the process of pushing the document buffers into the template placeholders, retrieving data from the document and pushing it into the JResponse buffer.
since |
11.1 |
---|
route
Route the application.
route() : void
Routing is the process of examining the request environment to determine which component should receive the request. The component optional parameters are then set in the request object to be processed when the application is being dispatched.
since |
11.1 |
---|
set
Modifies a property of the object, creating it if it does not already exist.
set(string $property, mixed $value = null) : mixed
since |
11.1 |
---|
Arguments
- $property
string
The name of the property.- $value
mixed
The value of the property to set.
Response
mixed
Previous value of the property.
setError
Add an error message.
setError(string $error) : void
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Arguments
- $error
string
Error message.
setProperties
Set the object properties based on a named array/hash.
setProperties(mixed $properties) : boolean
since |
11.1 |
---|---|
see | \JObject::set() |
Arguments
- $properties
mixed
Either an associative array or another object.
Response
boolean
setUserState
Sets the value of a user state variable.
setUserState(string $key, string $value) : mixed
since |
11.1 |
---|
Arguments
- $key
string
The path of the state.- $value
string
The value of the variable.
Response
mixed
The previous state, if one existed.
stringURLSafe
This method transliterates a string into an URL safe string or returns a URL safe UTF-8 string based on the global configuration
stringURLSafe(string $string) : string
since |
11.1 |
---|
Arguments
- $string
string
String to process
Response
string
Processed string
toString
Converts the object to a string (the class name).
toString() : string
triggerEvent
Calls all handlers associated with an event group.
triggerEvent(string $event, array $args = null) : array
since |
11.1 |
---|
Arguments
- $event
string
The event name.- $args
array
An array of arguments.
Response
array
An array of results from each function call.
Properties
_clientId
The client identifier.
since |
11.1 |
---|
Type(s)
integer
_messageQueue
The application message queue.
since |
11.1 |
---|
Type(s)
array
_name
The name of the application.
since |
11.1 |
---|
Type(s)
array
scope
The scope of the application.
since |
11.1 |
---|
Type(s)
string
requestTime
The time the request was made.
since |
11.1 |
---|
Type(s)
\date
startTime
The time the request was made as Unix timestamp.
since |
11.1 |
---|
Type(s)
integer
instances
JApplication instances container.
since |
11.3 |
---|
Type(s)
array
_errors
An array of error messages or Exception objects.