Joomla Application Object

The main applications are Administrator, Site, and Installation. With the CMSApplication, you can access many things in Joomla. For example, you can access configuration, input variables, menu or enqueue messages which are shown to the user.

The class files are located in the folder: libraries/src/Application.

To get CMS Application object:

use Joomla\CMS\Factory;
$app = Factory::getApplication();

It is an object of type JApplicationAdministrator or JApplicationSite depending on the application currently running.


1. allowCache($allow = null)

It is used to set or get the cachable state for the response. If the variable $allow is set, then the function sets the cachable state of the response. It always returns the current state.

2. appendBody($content)

It is used to append content to the body content.

3. enqueueMessage($msg, $type = self::MSG_INFO)

It enqueues a system message. For example,

4. getBody($asArray = false)

It returns the body content.

5. getDocument()

It is a method to get the application document object.

6. getHeaders()

Method to get the array of response headers to be sent when the response is sent to the client.

7. getMenu()

It returns the Menu object.

8. getMessageQueue($clear = false)

It gets the system message queue as array.

9. getPathway($name = null, $options = array())

It returns the Pathway object.

10. getRouter($name = null, $options = array())

It returns the Router object.

11. getSession()

It is a method to get the application session object.

12. getTemplate($params = false)

It gets the name of the current template.

13. isClient()

It is used to check the client interface by name. The function returns true if application is of given client type. For example,

isAdmin = $app->isClient('administrator');
isSite = $app->isClient('site');

14. isHttpsForced()

It checks if HTTPS is forced in the client configuration.

15. isSSLConnection()

It determines if the site is using a secure (SSL) connection.

16. login($credentials, $options = array())

Login authentication function.

17. logout($userid = null, $options = array()) 

Logout authentication function.

18. prependBody($content)

It prepends content to the body content.

19. redirect($url, $status = 303)

It is used to redirect to another URL.

20. setBody($content)

It sets the body content. If body content already defined, this will replace it.

21. setHeader($name, $value, $replace = false)

It is a method to set a response header. If the replace flag is set then all headers with the given name will be replaced by the new one. The headers are stored in an internal array to be sent when the site is sent to the browser.