2013-10-03 43 views
0

我試圖創建一個使用drupal_execute Drupal的節點,它工作正常。 唯一的問題是,我無法將新節點添加爲登錄用戶以外的其他用戶。不能創建新的Drupal 6個節點,作爲其他用戶,使用drupal_execute

好像$ form_state [ '值'] [ '名']沒有效果!

這甚至可能嗎?

任何幫助將不勝感激!

+0

你給這個其他用戶創建Drupal節點所需的權限嗎? – aaron

+0

我已經測試過不同的用戶名,可以從drupal表單創建節點。但我的問題仍然是如果甚至有可能使用drupal_execute創建另一個用戶的節點。 –

回答

1

https://drupal.org/node/178506#comment-726479 - 雖然它在第一次提到的Drupal 5.7,它適用於Drupal的6了。它的要點是,你必須(safely) impersonate another user。通過這樣做,您可以訪問用戶可以訪問的任何功能。

冒充用戶很簡單,只要

global $user; 
$original_user = $user; 
$old_state = session_save_session(); 
session_save_session(FALSE); 
$user = user_load(array('uid' => 1)); 

// Take your action here where you pretend to be the user with UID = 1 (typically the admin user on a site) 
// If your code fails, it's not a problem because the session will not be saved 
$user = $original_user; 
session_save_session($old_state); 

// From here on the $user is back to normal so it's OK for the session to be saved 

然後,你必須採取的動作是與你的形式排列運行drupal_execute()

+0

kekkis你是一個拯救生命的人! 我試圖覆蓋全球$用戶之前,它的工作。問題在於新的全球用戶保持登錄狀態,現在通過解決方案來恢復會話。 謝謝! –

相關問題