本文整理汇总了PHP中JUser::setError方法的典型用法代码示例。如果您正苦于以下问题:PHP JUser::setError方法的具体用法?PHP JUser::setError怎么用?PHP JUser::setError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUser
的用法示例。
在下文中一共展示了JUser::setError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerUser
public static function registerUser($profile)
{
$params = JComponentHelper::getParams('com_users');
// Initialise the table with JUser.
$user = new JUser();
$data = array();
if (!$profile->email) {
$profile->email = $profile->id + 200000 . '@sibdiet.net';
}
// Prepare the data for the user object.
$data['name'] = $profile->fname . ' ' . $profile->lname;
$data['username'] = (string) ($profile->id + 200000);
$data['email'] = JStringPunycode::emailToPunycode($profile->email);
$data['password'] = $profile->mobile;
$data['groups'][] = $params->get('new_usertype', 2);
// Bind the data.
if (!$user->bind($data)) {
$user->setError(JText::sprintf('COM_SIBDIET_ERR_REGISTRATION_BIND_FAILED', $user->getError()));
return false;
}
// Load the users plugin group.
JPluginHelper::importPlugin('user');
// Store the data.
if (!$user->save()) {
$user->setError($user->getError());
return false;
}
$config = JFactory::getConfig();
// Compile the notification mail values.
$data = $user->getProperties();
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$data['siteurl'] = JUri::root();
// Handle account activation/confirmation emails.
$emailSubject = JText::sprintf('COM_SIBDIET_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
$emailBody = JText::sprintf('COM_SIBDIET_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']);
// Send the registration email.
$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody, true);
// Check for an error.
if ($return !== true) {
$user->setError(JText::_('COM_SIBDIET_ERR_REGISTRATION_SEND_MAIL_FAILED'));
}
return $user->id;
}