我正在尝试在Drupal 6.20中创建一个简单的模块,如下所示:

<?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文件外,是否还需要更多的NE文件?

谢谢。

有帮助吗?

解决方案

我得到了解决方案。对于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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top