0
다양한 분류에 첨부 된 일부 컨텐츠 유형 (노드)이 있습니다. 특정 노드 유형의 경우 분류에 대한 유효성 검사를하고 싶습니다. 분류 유형을 참조하는 노드 유형과 해당 필드를 하드 코딩하고 싶지 않습니다. 그래서 나는 그들을 배열에 넣었다.Drupal - PHP Validation
그러나 필드 이름을 역 참조 할 수 없습니다. 이중 $$, 따옴표 등을 시도했지만 작동하지 않습니다. 내가하고 싶은 일이 가능한가?
다음은 작동시키려는 독립형 PHP입니다.
<?php
$node = (object) array(
'nid' => NULL,
'vid' => NULL,
'uid' => '1',
'type' => 'price_document',
'language' => 'und',
'field_taxonomy_price' => array(
'und' => array(
array(
'tid' => '94'
)
)
),
);
$nodes_to_check = array("price_document" => "field_taxonomy_price",
"package" => "field_taxonomy_package",
);
if (array_key_exists($node->type,$nodes_to_check)) {
$taxonomy_field = $nodes_to_check[$node->type];
print_r($taxonomy_field);
$tid = $node->field_taxonomy_price ['und'][0]['tid']; // <- this works but, how
//$tid = $node->"$$taxonomy_field" ['und'][0]['tid']; <- can I deref variable?
}
?>