Using the JFactory class
From Joomla! Documentation
Using the JFactory Class
Introduction[edit]
JFactory is the Joomla! Platform class, giving you access to the most important (mostly singletons) parts in Joomla. It contains multiple other objects, like the application one or the Joomla! global configuration.
JFactory::getApplication()[edit]
Returns the JApplicationCMS, through it you can access for the example do redirects, access the configuration and the input variables, the Menu or enqueue messages which are shown to the user.
- See Using the JApplication class for more details.
JFactory::getDocument()[edit]
Provides access to the current JDocument, with it you can set Meta data, add styles and scripts and more related to the document.
JFactory::getDbo()[edit]
Returns a database object. JDatabase methods are executed by chaining to the database object.
Examples:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = JFactory::getDbo()->getQuery(true);
- See also Selecting data using JDatabase
JFactory::getUser()[edit]
Returns the user object for the currently logged in user (JUser). The object provides access to preloaded values specific to the logged in user as well as methods within the class. If no user is logged in, the user is deemed a "guest" and the id of the user is set to zero.
JFactory::getDate()[edit]
Returns a How to use JDate instance, you can also add a time and a timezone offset to it. Without parameters it uses the current time.
JFactory::getMailer()[edit]
Provides access to the Joomla Mailer (wrapper around PHPMailer) for sending emails with Joomla.
- See also Sending email from extensions
JFactory::getConfig()[edit]
Returns a registry with the Joomla! configuration file (configuration.php), see JConfig for more details. To access single values you can use JFactory::getApplication()->get('configValue')
- See also Getting global configuration parameters
JFactory::getSession()[edit]
Returns the current visitors session. (Make sure Joomla! is called as Webapplication)