J'ai un script externe pour une application Web connectée à la base de données Joomla. Ceci est destiné à l'enregistrement de l'utilisateur Source: https://Gist.github.com/AdamMadrzejewski/2581730241748da89798
<?php
require_once __DIR__ . '/db_connect.php';
$type = '0';
$username = 'username';
$password = 'pass';
$name = 'john';
$mobile = '9090909090';
$email = '[email protected]';
$alias = strtr($name, array (' ' => '-'));
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
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_BASE.DS.'components'.DS.'com_users'.DS.'models'.DS.'registration.php');
$lang = JFactory::getLanguage();
$extension = 'com_users';
$base_dir = JPATH_SITE;
$language_tag = 'en-GB';
$reload = true;
$lang->load($extension, $base_dir, $language_tag, $reload);
$model = new UsersModelRegistration();
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
$block = '0';
$sendEmail = '0';
$activation = '1';
$data = array( 'username' => $username,
'name' => $name,
'email1' => $email,
'password1' => $password, // First password field
'password2' => $password, // Confirm password field
'sendEmail' => $sendEmail,
'activation' => $activation,
'mobile' => $mobile,
'groups' =>array("2","10"));
$response = $model->register($data);
echo $data['mobile'];
Le résultat attendu est de stocker toutes les valeurs, y compris un champ personnalisé appelé "mobile" dans la table #__users
mais il stocke toutes les valeurs sauf pour mobile, j'ai ajouté déclaré la variable
$mobile = null; // line 60 at root/libraries/joomla/user/user.php
Ajouter de la valeur à com_users/models/forms/registration.xml n'aide pas
<field
name="mobile"
type="text"
description="COM_USERS_DESIRED_USERNAME"
filter="mobile"
label="COM_USERS_REGISTER_USERNAME_LABEL"
message="COM_USERS_REGISTER_USERNAME_MESSAGE"
size="30" />
Mais de toute façon, il ne stocke pas que la valeur mobile dans la table
Où vais-je mal? Ce code appelle la fonction com_users/models/registration.php
public function register()
Où devrais-je modifier pour ajouter la valeur 'mobile'? Appréciez l'aide!
Le testcode suivant fonctionne
<?php
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__);
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_BASE . DS . 'components' . DS . 'com_users' . DS . 'models' . DS . 'registration.php');
//not necessary
//require_once(JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'application'.DS.'component'.DS.'helper.php';
$model = new UsersModelRegistration();
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
$language = JFactory::getLanguage();
$language->load('com_users', JPATH_SITE);
$type = '0';
$username = 'username';
$password = 'pass';
$name = 'john';
$mobile = '9090909090';
$email = '[email protected]';
$alias = strtr($name, array(' ' => '-'));
$username = 'adam';
$name = 'adam24';
$email = '[email protected]';
$password = 'adam';
$block = '0';
$sendEmail = '0';
$activation = '1';
$data = array('username' => $username,
'name' => $name,
'email1' => $email,
'password1' => $password, // First password field
'password2' => $password, // Confirm password field
'sendEmail' => $sendEmail,
'activation' => $activation,
'mobile' => $mobile,
'groups' => array("2", "10"));
$response = $model->register($data);
echo $data['mobile'];
echo $model->register($data);
if (version_compare(PHP_VERSION, '5.3.1', '<')) {
die('Your Host needs to use PHP 5.3.1 or higher to run this version of Joomla!');
}
?>
<!-- db result -->
<tr>
<th>id</th>
<th>name</th>
<th>username</th>
<th>email</th>
<th>password</th>
<th>block</th>
<th>sendEmail</th>
<th>registerDate</th>
<th>lastvisitDate</th>
<th>activation</th>
<th>params</th>
<th>lastResetTime</th>
<th>resetCount</th>
<th>otpKey</th>
<th>otep</th>
<th>requireReset</th>
<th>mobile</th>
</tr>
<tr>
<td>382</td>
<td>adam24</td>
<td>adam</td>
<td>[email protected]</td>
<td>$2y$10$CWsR0Ab9AZNvze2l/2Teiek3mzZ3EqyxnAzuYcv9CTaMCeSud5pza</td>
<td>1</td>
<td>0</td>
<td>2015-10-26 22:16:16</td>
<td>NULL</td>
<td>fa37ff46e1be16c6029723c395c0f156</td>
<td>{}</td>
<td>NULL</td>
<td>0</td>
<td></td>
<td></td>
<td>0</td>
<td>9090909090</td>
</tr>
$ mobile = null; // ligne 60 à la racine/libraries/joomla/user/user.php
La variable mobile ne doit pas être déclarée dans la bibliothèque. La méthode Table-> bind est vraiment flexible.
Pendant le chargement via JFactory :: getUser ('adams_id'); il a aussi chargé le mobile.