Using the JFactory class: Difference between revisions

From Joomla! Documentation

m JFactory::getUser(): rewording in the description, fixed deadlink
 
(3 intermediate revisions by 2 users not shown)
Line 17: Line 17:
Provides access to the current JDocument, with it you can set Meta data, add styles and scripts and more related to the document.
Provides access to the current JDocument, with it you can set Meta data, add styles and scripts and more related to the document.


*See [[S:MyLanguage/Using the JFactory class/Adding JavaScript and CSS to the page|Adding JavaScript and CSS to the page]]
*See [https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page Adding JavaScript and CSS to the page]


== JFactory::getDbo() ==
== JFactory::getDbo() ==


Returns a database object, with it you query to the database <tt>($query = JFactory::getDbo()->getQuery(true))</tt>, secure your input before sending it and load entries.
Returns a database object. [https://api.joomla.org/cms-3/classes/JDatabaseDriver.html JDatabase methods] are executed by chaining to the database object.


*See also [[S:MyLanguage/Using the JFactory class/Selecting data using JDatabase|Selecting data using JDatabase]]
Examples:
 
<source lang="php">
$db = JFactory::getDbo();
$query = $db->getQuery(true);
</source>
 
<source lang="php">$query = JFactory::getDbo()->getQuery(true);</source>
 
*See also [https://docs.joomla.org/Selecting_data_using_JDatabase Selecting data using JDatabase]


== JFactory::getUser() ==
== JFactory::getUser() ==


Returns the current Joomla! user object (JUser), with it you can access information and methods related to users. It is also created for guests, where the id is zero.
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.


*See [[S:MyLanguage/Using the JFactory class/Accessing the current user object|Accessing the current user object]]  
*See [https://docs.joomla.org/Accessing_the_current_user_object Accessing the current user object]


== JFactory::getDate() ==
== JFactory::getDate() ==
Line 43: Line 52:
== JFactory::getConfig() ==
== JFactory::getConfig() ==


Returns a registry with the Joomla! configuration file (configuration.php), see [[S:MyLanguage/Using the JFactory class/JConfig|JConfig]] for more details. To access single values you can use <tt>JFactory::getApplication()->get('configValue')</tt>
Returns a registry with the Joomla! configuration file (configuration.php), see JConfig for more details. To access single values you can use <tt>JFactory::getApplication()->get('configValue')</tt>


*See also [[S:MyLanguage/Using the JFactory class/Getting global configuration parameters|Getting global configuration parameters]]
*See also Getting global configuration parameters


== JFactory::getSession() ==
== JFactory::getSession() ==

Latest revision as of 03:46, 19 October 2019

Tutorial
Using the JFactory Class
Joomla! 
≥ 3.0
<series

Introduction

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()

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.

JFactory::getDocument()

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()

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);

JFactory::getUser()

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()

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()

Provides access to the Joomla Mailer (wrapper around PHPMailer) for sending emails with Joomla.

JFactory::getConfig()

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()

Returns the current visitors session. (Make sure Joomla! is called as Webapplication)

External Links