我是否在Drupal模块中引用了错误的民意调查内容类型?

时间:2010-08-18 20:56:57

标签: drupal drupal-modules

我有以下模块,它影响用户如何到达两种不同的内容类型,“问题”和“轮询”。问题是CCK内容类型,民意调查是默认的民意调查内容类型,但它适用于问题,带走的是用户,即

http://sparechangenews.net/content/are-you-seeing-evidence-economic-recovery(这是一个“问题”内容类型)

http://www.sparechangenews.net/question/270(270是NID)

但是

http://sparechangenews.net/question/what-would-you-see-more-spare-change-news(这是民意调查)

只是转到正常的网址。我需要重定向,因为我有一个视图检查引用它的节点的NID(从URL中拉出),并将它们用作超级注释(ripped from this tutorial)的排序。我在模块中引用了错误的民意调查吗?有什么提示吗?

<?php
/**
 * @file
 * An example module to redirect the path from a node view for at
 * specific type to a view.
 */

/**
 * Implementation of hook_init().
 */
function example_init() {
  // Using arg() instead of menu_get_item(). Rumor has it menu_get_item
  // can occassionally cause WSOD.
  // We make sure arg(2) is empty so we do not redirect on edit or other
  // node sub pages.
  if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
    $node = node_load(arg(1));
    if ($node->type == 'answer') {
      drupal_goto('question/'. $node->field_answer[0]['nid']);
    }
    elseif ($node->type == 'poll' || $node->type == 'question') {
      drupal_goto('question/'. $node->nid);
    }
  }
}

1 个答案:

答案 0 :(得分:1)

我不确定您的代码有什么问题,但您可能想要查看的替代方法是http://drupal.org/project/path_redirecthttps://drupal.org/project/pathauto。您可以为特定内容类型设置自动别名,还可以使用路径重定向来维护旧别名并重定向到新别名。

然而,我觉得你可能应该能够在没有任何重定向的情况下实现你想要做的事情。如果您只是想将nid作为视图参数,为什么不在“提供默认参数”下检查“URL中的节点ID”,或者选中“PHP”并编写一些自定义代码,如上所示:

$nid = arg(1);

无论如何,我建议解决问题,在没有重定向的情况下将所需内容添加到视图中,因为它会降低复杂性(和开销)。