2013-12-21 31 views
0

我包括jQuery庫:DRUPAL_UID未設置

function zenbws_preprocess_html() { 
    drupal_add_library('system', 'jquery.cookie'); 
} 

的假設是,該cookie將被設置,但我看不到DRUPAL_UID在瀏覽器中的cookie列表。加var cookie_value = jQuery.cookie("DRUPAL_UID");不會返回任何內容。

我錯過了什麼?

+0

Drupal沒有設置這樣的cookie – Clive

回答

0

你可以做到這一點通過你的template.php文件中手動像你與磁帶庫...使用JavaScript中

drupal_add_js(array('userid' => $user->uid), 'setting'); 

訪問:

Drupal.settings.userid 

如果你真的想要它在餅乾,然後你可以使用你的代碼來設置它:

jQuery.cookie('userid', Drupal.settings.userid, { expires: 7 }); // Lasts 1 week 

和訪問:

jQuery.cookie('userid'); 
0

此問題已被討論here

hook_init實現創建一個新模塊。

function [YOUR_MODULE]_init() 
{ 
    global $user; 
    drupal_add_js(array('user_js_uid' => $user->uid), 'setting'); 
} 

您現在已將用戶uid放在javascript變量user_js_uid中。