开发者

what's these lines meaning in hook_menu?

Defining page arguments is useful because you c开发者_JS百科an call the same callback from different menu items and provide some hidden context for the callback through the page arguments.

i don't follow this well, expect someone can make an example to me. thank you.


This a very quick exemple. This create a new menu entry, which accept two argument. As for the exemple, I choose $year and $month here. So I'm able to pass a $year and a $month to a page, wich a used in a custom form to do some stuff.

So, you are here able to set a context (a year/month) for a form in a custom page.

/**
 * 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;
}

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜