drupal7中的用户添加于更新(完全个人开发所得,如有不妥之处请大虾指出)

时间:2022-06-26 22:15:52
                                $newuser = array(
                                    'name' => autocheck($value[11]),
                                    'pass' => 'xiaoran',
                                    'mail' => autocheck(@$value[12]),
                                    'init' => autocheck(@$value[12]),
                                    'status' => 1,
                                    'roles' => array($keys => $values),    //这里为给用户分配角色

                                    'access' => REQUEST_TIME,

                                     以下为 手动为用户创建的字段:

                                     'field_user_daibiao' => array(LANGUAGE_NONE => array(array('value' => autocheck(@$value[0])))),

                                       .....................

                                );


                             //保存   user_save(nulll,$newuser);    ok  保存完成!

                                        

                           

                            //更新   更新操作你要让drupal知道你更新谁,并且还要是在数据库中已存在的用户信息,才能进行更新操作,所以这里要使用user_load()加载用户信息

                               $account = user_load($uid);

                                user_save($account,$newuser);

                               ok   更新完成!


简单吧!快试试吧!