2

I am building a component which has its own registration form. Most of its properties work well but I couldn't set the usertype or usergroup of the user in J1.6 or J2.5. I am not fully knowledgeable about platforms, I am trying something first for me. Here is mye piece of code in model class

    // Prepare the data for the user object. Data comes from controller
    $data['name']       = $data['companyName'];
    $data['username']   = MyCompHelper::getCreatedUserName($data['type']);//for system created username based on the type from form 
    $data['email']      = $data['email1'];

    $data['password']   = (!empty($data['password1'])) ? $data['password1'] : '';
    $data['usertype']       = $params->get('new_usertype',2);

Then I bind the data to user object and save it but user isn't assigned to any group. So I think I should correct this

$data['usertype']       = $params->get('new_usertype',2);

part but which way, what I write instead

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
freezer
  • 531
  • 1
  • 11
  • 28
  • Welcome to StackOverflow. Unfortunately, SO is not a Research Assistant, please refer to [What Can I Ask Here](http://stackoverflow.com/faq) to see what is appropriate to ask. Please provide specific questions, examples about what have you tried, or what the specific problem is. – GDP Jul 02 '12 at 22:28
  • so sorry about my poor question and english also these posts are my firsr questions on foreign platforms. My question is how can ı save the usertype form com_users parameters and appropriate record also be added to user group map table but ı couldnt do that which part of my code should be changed or what ı should add to my code to do what I want to do. I just imitate the core registration part but additional functionalities. everything goes right except usertype and group. – freezer Jul 02 '12 at 23:25
  • No problem :)...just adjust your question to be more specific, and ideally reference where in the code you are having trouble. Most folks don't read your code, try to understand what is supposed to be happening, and then try to understand where you are stuck. – GDP Jul 03 '12 at 01:15
  • Isn't here anybody knows this :S How can I solve this :S – freezer Jul 04 '12 at 22:08

1 Answers1

1

In Joomla 1.6 usertype is deprecated. use groups instead.
You can find the "default group" by calling:

$conf = JComponentHelper::getParams('com_users');
$defUserGroup = $conf->get('new_usertype', 2);

and then use it as:

$inst = JUser::getInstance();
$inst->set('groups', array($defUserGroup));
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129