通过php的Drupal字段值

时间:2015-07-30 13:27:48

标签: php drupal drupal-7

我正在尝试通过作者ID过滤Biblio节点的视图。在人员配置文件中,我有一个字段(field_author_id_ccsi),其中包含ID(整数)。如何通过PHP在视图的上下文过滤器中引用它(在高级下)。这是我到目前为止所做的,但它不起作用:

$node = node_load(arg(1));
if($node->field_author_id_ccsi[und][0]->value)
   return $node->field_author_id_ccsi[und][0]->value;
} 
else { 
   return; 
}

2 个答案:

答案 0 :(得分:1)

您需要打开阵列对象$ node-> field_author_id_ccsi,以查看ID所在的位置,然后向下钻取。

例如: 让$node->field_author_id_ccsi['und']成为你感兴趣的阵列。 您需要调查所述数组的内容以查看该数组中的实际内容。如果ID是数组中的第一个元素,那么:

echo $node->field_author_id_ccsi['und'][0];

将在视图中的屏幕上显示整数。

然而,var_dump($node->field_author_id_ccsi['und']);会告诉您ID的确切位置 - 如果存在,print_r();也是如此。如果数组是多维数组,则可能需要使用foreach()遍历数组。

答案 1 :(得分:0)

以下是我使用的代码:

$node = node_load(arg(1));
if($node && isset($node->field_author_id_ccsi)) {
    return $node->field_author_id_ccsi['und'][0]['value'];
}
return;