hook_menu中这些行的含义是什么?

时间:2011-03-30 08:30:10

标签: drupal-6

定义页面参数很有用,因为您可以从不同的菜单项调用相同的回调,并通过页面参数为回调提供一些隐藏的上下文。

我不这么做,期待有人可以为我做一个榜样。谢谢。

1 个答案:

答案 0 :(得分:0)

这是一个非常快速的例子。这将创建一个新的菜单项,它接受两个参数。至于例子,我在这里选择$year$month。所以我可以将$year$month传递给一个页面,在自定义表单中使用它来做一些事情。

因此,您可以在自定义页面中为表单设置上下文(一年/月)。

/**
 * Implementation of hook_menu().
 */
function exemple_menu() {
  $items = array();
  $items['mydate/%/%'] = array(
    'title' => 'Exemple', // NOTE: t() not needed
    'page callback' => 'mydate_page',
    'page arguments' => array(1, 2),
    'access callback' => TRUE, // no access check
  );
  $return $items;
}

/**
 * Page callback.
 */
function mydate_page($year = null, $month = null) {
  if (isset($year) && isset($month)) {
    $output = drupal_get_form('myFormContentByDate', $year, $month);
  }
  else {
    drupal_set_message('You need to select a date', 'warning');
  }
  return $output;
}

希望有所帮助。

相关问题