在Drupal 6中将URI作为URL参数传递

时间:2010-06-15 11:42:47

标签: drupal url-rewriting

我在尝试将绝对URI作为参数传递并且启用了干净URL时遇到了问题。

我的hook_menu()设置如下:


function mymodule_menu() {
  return array(
    'page/%' => array(
      'title' => 'DBpedia Display Test',
      'page callback' => 'mymodule_dbpedia_display',
      'page arguments' => array(1),
    ),
  );
}

并在页面回调中:


function mymodule_dbpedia_display($uri) {
  // Make an HTTP request for this URI
  // and then render some things
  return $output;
}

我希望以某种方式将完整的URI(例如“http://dbpedia.org/resource/Coffee”)传递给我的页面回调。我已经尝试了一些事情,到目前为止没有任何工作......

  1. http://mysite.com/page/http%3A%2F%2Fdbpedia.org%2Fresource%2FCoffee
    完全打破Drupal的重写
  2. http://mysite.com/page/?uri=http%3A%2F%2Fdbpedia.org%2Fresource%2FCoffee
    提供404
  3. http://mysite.com/page/http://dbpedia.org/resource/Coffee
    只返回“http:”,这很有意义
  4. 我可能会使用$ _GET来提取整个查询字符串,但我想我希望有更多'Drupal'解决方案。有什么建议吗?

5 个答案:

答案 0 :(得分:2)

之前我遇到过这个问题,尝试做同样的事情(RDF浏览)。我通过在URI上使用rawurlencode和rawurldecode来解决它。

所以在创建链接时

l('Click Here', 'page/' . rawurlencode($uri));

当使用$ uri变量时,执行rawurldecode();

$uri = rawurldecode($uri);

它将为您提供类似

的URI
http://mysite.com/page/http%253A%252F%252Fdbpedia.org%252Fresource%252FCoffee

答案 1 :(得分:1)

如果网址的来源是您控制的,为什么不使用可逆编码(如base64)对字符串进行编码,从而删除任何棘手的字符,然后在执行菜单回调时进行解码。例如:

$link = 'http://www.example.com?uri='. base64_encode($uri);

...


function mymodule_dbpedia_display($uri) {

$uri = base64_decode($uri);
// Make an HTTP request for this URI
// and then render some things
return $output;
}

答案 2 :(得分:1)

不使用page/%,而是使用page/%menu_trail%menu_trail会将网址的其余部分作为单个字符串传递,在您的示例中,该字符串将作为$uri传递给菜单回调。

答案 3 :(得分:0)

这应该有效;这是一个known bug in Drupal。您可以尝试该线程中的补丁,但最好的选择可能是在URL编码之上进行不同的编码,正如其他人所建议的那样。

答案 4 :(得分:0)

只要你编码自己的URI,这比所有这些要容易得多 - 阅读这些文档,所有秘密都将被揭示:drupal_urlencode()

干杯

相关问题