我正在嘗試創建一個新的Drupal 7用戶,然後將該用戶的UID分配給一個變量。我想存儲這個UID,以便我可以創建一個新節點並將該用戶分配爲所有者。以編程方式創建Drupal用戶,然後存儲新用戶的UID
問題:有誰知道如何獲得新創建的用戶的UID?
我的代碼:
// CREATE USER
$newUser = array(
'name' => $refereeUsername,
'pass' => $refereePassword,
'mail' => $refereeEmail,
'status' => 1,
'init' => $refereeEmail,
'roles' => array(
2 => 'authenticated',
53 => 'Referer',
),
);
user_save($usera, $newUser);
// MY ATTEMPT TO GET THE NEWLY CREATED USER ID
$uidn = $usera->uid;
// CREATE NODE
$node = new stdClass;
$node->type = 'referee';
$node->title = 'Referee report for xx';
$node->uid = $uidn;
$node->status = FALSE;
$node->field_testff['und'][0]['value'] = "testworked";
node_object_prepare($node);
node_save($node);
怎麼叫數據庫或模型的UID?它實際上是UID還是僅僅是id? –
它實際上是UID。 – sephiith