开发者

Use the user.module API to create user in Drupal 7

I am trying to use user_save() in Drupal 7 to add new accounts to the system.

The function is defined as user_save($account, $edit = array(), $category = 'account').

According to the documentation, the variable $account is a user object. How do I put together a user object that the f开发者_运维问答unction can process?


Here is a comment that may help you out a little regarding the user object: User Object. Another way to see what the user object holds is to do:

<?php
  global $user;
  print_r($user);
?>

Here is a very basic example of creating a new user with user_save():

<?php    
  $edit = array(
    'name' => 'New User',
    'pass' => 'password',
    'mail' => 'myemail@example.com',
    'status' => 1,
    'language' => 'en',
    'init' => 'myemail@example.com',
    'roles' => array(2 => 'authenticated user'),
  );

  user_save(NULL, $edit);
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜