【发布时间】:2012-07-05 23:14:32
【问题描述】:
我正在尝试使用 entity_extract_ids($entity_type, $entity) 其中:
$entity_type = 实体类型;例如“节点”或“用户”。
$entity = 从中提取值的实体。
我从来没有使用过这个函数,不明白第二个参数(即$entity)应该是什么。
我希望看到使用此函数的示例代码。谢谢。
【问题讨论】:
标签: drupal drupal-7 drupal-entities
我正在尝试使用 entity_extract_ids($entity_type, $entity) 其中:
$entity_type = 实体类型;例如“节点”或“用户”。
$entity = 从中提取值的实体。
我从来没有使用过这个函数,不明白第二个参数(即$entity)应该是什么。
我希望看到使用此函数的示例代码。谢谢。
【问题讨论】:
标签: drupal drupal-7 drupal-entities
这个函数返回array($id, $vid, $bundle);
例子:
// Define $entity_type.
// Could be 'node', 'user', 'file', 'taxonomy_term' etc.
$entity_type = 'node';
// Get $entity object, in our case $node with nid = 1
$entity = node_load(1);
// print_r will give us something like:
// Array
// (
// [0] => 1
// [1] => 4
// [2] => page
// )
// Where [0] is nid, [1] is vid and [2] is bundle name of a node with nid = 1
print_r(entity_extract_ids($entity_type, $entity));
最好使用这样的函数:
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
【讨论】: