简体   繁体   English

Drupal动态内部重定向

[英]Drupal dynamic internal redirect

What I want is pretty simple. 我想要的很简单。 I have registered a path 我已经注册了一条路径

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

When this menu item is triggered, I want to redirect (without changing the url) to a taxonomy page, of which the term is chosen in a function that runs when this function is called. 触发此菜单项时,我想重定向(而不更改URL)到分类页面,该分类页面是在调用此函数时运行的函数中选择的。

How can I do this (especcially without changing the url) ? 我该怎么做(尤其是不更改url)?

You can't call taxonomy_term_page directly as your page callback as you'd need to provide a load function to load the term, which is just going to be too difficult with the setup you've got. 您不能直接在page callback调用taxonomy_term_page ,因为您需要提供一个加载功能来加载术语,而这对于您的设置来说太困难了。

Instead, define your own page callback as an intermediary and just return the output from taxonomy_term_page directly: 而是将您自己的页面回调定义为中介,然后直接从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