2012-01-05 23 views
2

我試圖在drupal中實現hook_menu。drupal 7中未定義的偏移錯誤

function menufun_menu() { 
    $items['menufun'] = array(
     'title' => 'Menu Fun', 
     'title callback' => 'menufun_title', 
     'page callback' => 'menufun_greeting', 
     'file' => 'menufun_greeting.inc', 
     'page arguments' => array('aaa', 'bbb', 'ccc', 'ddd'), 
     'access callback' => 'user_access', 
     'access arguments' => array('receive greeting'), 
     'type' => MENU_NORMAL_ITEM, 
     'weight' => -1, 
    ); 

    $items['menufun/farewell'] = array(
     'title' => 'Farewell', 
     'page callback' => 'menufun_farewell', 
     'file' => 'menufun_greeting.inc', 
     'access callback' => 'user_access', 
     'access agruments' => array('receive greeting'), 
     'type' => MENU_NORMAL_ITEM, 
    ); 

    return $items; 
} 

然而,上面的代碼將區分這2個錯誤:

Notice: Undefined offset: 0 in _menu_check_access() (line 619 of /Applications/XAMPP/xamppfiles/htdocs/drupal/includes/menu.inc). 
Notice: Undefined offset: 1 in _menu_check_access() (line 619 of /Applications/XAMPP/xamppfiles/htdocs/drupal/includes/menu.inc). 

上述2個錯誤將不會顯示如果我改變

'access callback' => 'user_access', 

'access callback' => TRUE, 

但我已經以管理員身份登錄r,並且我向所有用戶授予訪問權限,並且我嘗試重新加載模塊,嘗試重新安裝drupal以使數據庫變得乾淨,但我仍然遇到同樣的錯誤,任何建議?

回答

5

您在第二個菜單定義中拼寫了「參數」錯誤。

'access agruments' => array('receive greeting'), 

應該

'access arguments' => array('receive greeting'), 

當你打開它'access callback' => TRUE,它忽略的參數,因爲它被告知,這並不需要做任何檢查,但實際的回調它試圖找到access arguments但不能。

+0

啊......我明白了。它的工作原理,謝謝! – qkzhu 2012-01-05 01:48:30

+0

很高興幫助!不要忘記標記答案,如果他們工作,以便未來的人知道這是解決你的問題。 – jprofitt 2012-01-05 01:53:40

+0

瞭解,謝謝你的解釋:) – qkzhu 2012-01-05 01:59:12