Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Drupal6上从hook_init中调用用户_save失败_Drupal - Fatal编程技术网

在Drupal6上从hook_init中调用用户_save失败

在Drupal6上从hook_init中调用用户_save失败,drupal,Drupal,我有一个实现hook_init的模块 在这一点上,我有一个案例,我试图调用像保存 user_save (''); 我想这应该可以,因为我没有设置uid,所以它应该创建一个新的uid。它还说,应该允许$array为空。 但是,这总是返回FALSE 我还尝试在$array中设置这些值,但这也不起作用: $foo = array( 'name' => 'the new user', 'mail' => 'the new us

我有一个实现hook_init的模块

在这一点上,我有一个案例,我试图调用像保存

user_save ('');
我想这应该可以,因为我没有设置uid,所以它应该创建一个新的uid。它还说,应该允许$array为空。 但是,这总是返回FALSE

我还尝试在$array中设置这些值,但这也不起作用:

        $foo = array(
            'name' => 'the new user',
            'mail' => 'the new user mail',
            'pass' => user_password(),
            'status' => 1,
            );
        $new_user = user_save ('', $foo);

查看文档:

参数
$account用户要修改或添加的$user对象。如果省略$user->uid,将添加一个新用户。
$array(可选)要保存的字段和值的数组。例如,数组('name'=>'My name');将字段设置为NULL会将其从数据列中删除


因此,当调用
user\u save()
时,第一个参数必须是用户对象。如果该用户对象没有uid,或者是与您的情况类似的字符串,则将创建一个新用户。这里第二个参数是必需的。不需要使用该函数,但由于它保存了您想要保存的所有值,因此创建一个完全没有数据的用户不会有太大的困难。没有密码、用户名等的用户有什么用呢?所以也需要最少的数据,这样Drupal就知道要保存什么了。

事实证明,我只需保存用户的保存(“”,数组(name=>$newusername));然后,在用户登录后,我可以让他们填写个人资料(包括密码和覆盖用户名)。