繁体   English   中英

Drupal动态内部重定向

[英]Drupal dynamic internal redirect

我想要的很简单。 我已经注册了一条路径

function spotlight_menu() {
    $items = array();

    $items['congres'] = array(
        'title' => 'Congres',
        'title arguments' => array(2),
        'page callback' => 'taxonomy_term_page',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );

    return $items;
}

触发此菜单项时,我想重定向(而不更改URL)到分类页面,该分类页面是在调用此函数时运行的函数中选择的。

我该怎么做(尤其是不更改url)?

您不能直接在page callback调用taxonomy_term_page ,因为您需要提供一个加载功能来加载术语,而这对于您的设置来说太困难了。

而是将您自己的页面回调定义为中介,然后直接从taxonomy_term_page返回输出:

function spotlight_menu() {
  $items = array();

  $items['congres'] = array(
    'title' => 'Congres',
    'page callback' => 'spotlight_taxonomy_term_page',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

function spotlight_taxonomy_term_page() {
  // Get your term ID in whatever way you need
  $term_id = my_function_to_get_term_id();

  // Load the term
  $term = taxonomy_term_load($term_id);

  // Make sure taxonomy_term_page() is available
  module_load_include('inc', 'taxonomy', 'taxonomy.pages');

  // Return the page output normally provided at taxonomy/term/ID
  return taxonomy_term_page($term);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM