JFactory: Difference between revisions
From Joomla! Documentation
New page: <span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{Description:JFactory}}
===Defined in===
lib... |
No edit summary |
||
| Line 57: | Line 57: | ||
|Return a reference to the JDate object | |Return a reference to the JDate object | ||
|} | |} | ||
===Importing=== | ===Importing=== | ||
<source lang="php">jimport( 'joomla.factory' );</source> | <source lang="php">jimport( 'joomla.factory' );</source> | ||
Revision as of 17:35, 25 March 2010
[Edit Descripton] Template:Description:JFactory
Defined in
libraries/joomla/factory.php
Methods
| Method name | Description |
|---|---|
| getApplication | Get a application object |
| getConfig | Get a configuration object |
| getSession | Get a session object |
| getLanguage | Get a language object |
| getDocument | Get a document object |
| getUser | Get an user object |
| getCache | Get a cache object |
| getACL | Get an authorization object |
| getTemplate | Get a template object |
| getDBO | Get a database object |
| getMailer | Get a mailer object |
| getXMLParser | Get an XML document |
| getEditor | Get an editor object |
| getURI | Return a reference to the JURI object |
| getDate | Return a reference to the JDate object |
Importing
jimport( 'joomla.factory' );
[Edit See Also] Template:SeeAlso:JFactory
Examples
<CodeExamplesForm />
Create a fresh user
JFactory provides a simple means of organising the main singleton objects required by the Joomla Framework.
Defined in
libraries/joomla/factory.php
Methods
| Method name | Description |
|---|---|
| getApplication | Get a application object |
| getConfig | Get a configuration object |
| getSession | Get a session object |
| getLanguage | Get a language object |
| getDocument | Get a document object |
| getUser | Get an user object |
| getCache | Get a cache object |
| getACL | Get an authorization object |
| getDbo | Get a database object |
| getMailer | Get a mailer object |
| getFeedParser | Get a parsed XML Feed Source |
| getXMLParser | Get an XML document |
| getXML | Reads a XML file. |
| getEditor | Get an editor object |
| getURI | Return a reference to the JURI object |
| getDate | Return the JDate object |
| getStream | Creates a new stream object with appropriate prefix |
Importing
jimport( 'joomla.factory' );
Examples
Code Examples
Create a fresh user
/*
I handle this code as if it is a snippet of a method or function!!
First set up some variables/objects
*/
// get the ACL
$acl =& JFactory::getACL();
/* get the com_user params */
jimport('joomla.application.component.helper'); // include libraries/application/component/helper.php
$usersParams = &JComponentHelper::getParams( 'com_users' ); // load the Params
// "generate" a new JUser Object
$user = JFactory::getUser(0); // it's important to set the "0" otherwise your admin user information will be loaded
$data = array(); // array for all user settings
// get the default usertype
$usertype = $usersParams->get( 'new_usertype' );
if (!$usertype) {
$usertype = 'Registered';
}
// set up the "main" user information
$data['name'] = $firstname.' '.$lastname; // add first- and lastname
$data['username'] = $username; // add username
$data['email'] = $email; // add email
$data['gid'] = $acl->get_group_id( '', $usertype, 'ARO' ); // generate the gid from the usertype
/* no need to add the usertype, it will be generated automaticaly from the gid */
$data['password'] = $password; // set the password
$data['password2'] = $password; // confirm the password
$data['sendEmail'] = 1; // should the user receive system mails?
/* Now we can decide, if the user will need an activation */
$useractivation = $usersParams->get( 'useractivation' ); // in this example, we load the config-setting
if ($useractivation == 1) { // yeah we want an activation
jimport('joomla.user.helper'); // include libraries/user/helper.php
$data['block'] = 1; // block the User
$data['activation'] =JUtility::getHash( JUserHelper::genRandomPassword() ); // set activation hash (don't forget to send an activation email)
}
else { // no we need no activation
$data['block'] = 0; // don't block the user
}
if (!$user->bind($data)) { // now bind the data to the JUser Object, if it not works....
JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
return false; // if you're in a method/function return false
}
if (!$user->save()) { // if the user is NOT saved...
JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
return false; // if you're in a method/function return false
}
return $user; // else return the new JUser object
This example was originally contributed by User:Bembelimen
Chris Davenport 15:44, 17 April 2011 (CDT) Edit comment
This example was originally contributed by User:Bembelimen