I've searched and found a way to do this with JUser but when I try the script it says an include file can't be found and it doesn't exist on the server. I don't know if this is different for Joomla 3.0 so I was asking for help. Here's the script I tried:
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$app = JFactory::getApplication('site');
$app->initialise();
require_once JPATH_ROOT.DS.'components'.DS.'com_users'.DS.'models'.DS.'registration.php';
require_once JPATH_ROOT.DS.'libraries'.DS.'joomla'.DS.'application'.DS.'component'.DS.'helper.php';
$model = new UsersModelRegistration();
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
$username = 'jimporttest';
$name = 'J Port2';
$email = 'test @ mail.com';
$password = 'test';
$data = array( 'username' => $username,
'name' => $name,
'email1' => $email,
'password1' => $password, // First password field
'password2' => $password, // Confirm password field
'block' => 0 );
echo $model->register($data);
?>
Unless your file is in the root folder where the Joomla system is installed, this error is definitely expected.
returns the working files path. Therefore you may need to modify the path accordingly. Use
to make sure the 'include' folder in the same path as JPATH_BASE retuns. For instance, if your file is in the 'www/example/test' folder, then use
to get the correct base path.
Also I found some errors in your codes. Use this working codes for the testing purposes.
'../../' part of the
depends on the deviation of root folder as I explained earlier.
here is the code you can use.
you have to use the JPATH_BASE in the require_once clause (you are using JPATH_BASE_ROOT which is not defined). Also in JOOMLA 3.0 the helper.php it is not in that position.
Try this code:
I've tried that in my joomla 3.0 installation and it works.
Andrea
For >=Joomla 3 we need to do use the following code instead. Changed from "JModel" to "JModelLegacy". Click here to view in detail.