2010-12-20 226 views
0

我試圖按照以下步驟創建在Drupal 6.20一個簡單的模塊:hook_menu給予404

<?php 

function example_help($section) { 
    switch ($section) { 
    case 'admin/modules#description': 
     return t('This module implements an example form.'); 
    } 
} 

function example_menu($may_cache) { 
    $items = array(); 
    if ($may_cache) 
    { 
    $items[] = array(
     'path' => 'example', 
     'title' => t('Example'), 
     'callback' => 'example_page', 
     'access' => TRUE, 
     'type' => MENU_NORMAL_ITEM 
    ); 
    } 
    return $items; 
} 

function example_page() { 
    return drupal_get_form('example_page_form'); 
} 

function example_page_form() { 
    $form['fullname'] = array(
    '#type' => 'textfield', 
    '#title' => t('Enter your full name'), 
); 
    $form['submit'] = array(
    '#type' => 'submit', 
    '#value' => t('Save'), 
); 
    return $form; 
} 

function example_page_form_submit($form_id, $form_values) { 
    ...some code 
} 

但每當我在http://mysite.com/example我打字,其被重定向至404。請幫助。我對Drupal技術很陌生。除.info和.module文件之外,還有其他需要的文件嗎?

謝謝。

回答

0

我得到了解決方案。對於Drupal 6.X,它的菜單鉤子應該如下:

function example_menu() { 
    $items = array(); 
    $items['example'] = array(
     'title' => 'List', 
     'page callback' => 'example_page', 
     'access callback' => 'user_access', 
     'access arguments' => array('access content'), 
     'weight' => -10, 
     'type' => MENU_DEFAULT_LOCAL_TASK, 
    ); 
    return $items; 
}