2016年7月1日

Drupal 7 的 node 結構

7.x - Node object core structure (不含 fields)

$node->nidNode ID.
$node->vidThe revision ID of the current version of this node.
$node->typeType of node (e.g. book, page, forum), which is also the entity bundle.
$node->languageThe default language for this node.
$node->titlePage (or, more accurately, node) title.
$node->uidUser ID of node creator.
$node->statusunpublished/published (NODE_NOT_PUBLISHED | NODE_PUBLISHED).
$node->createdUNIX timestamp of node creation date.
$node->changedUNIX timestamp of last time node was changed.
$node->commentWhether comments are allowed on this node (COMMENT_NODE_HIDDEN | COMMENT_NODE_CLOSED | COMMENT_NODE_OPEN)
$node->promotePromoted to front page (NODE_NOT_PROMOTED | NODE_PROMOTED).
$node->stickySticky (NODE_NOT_STICKY | NODE_STICKY).
$node->tnidThe node ID of the translation source (or parent, if node is a translation).
$node->translateDoes the translation need to be updated (0|1)?
$node->revision_uidThe user ID of the user who created the current revision.
$node->bodyArray. Body content of node. Long text field with summary.
Note: Don't assume that this field will exist, as it is possible to remove it via Manage Fields on each content type. Similarly, modules that define a custom node content type may not even attach a body in the first place.
$node->logMessage left by the creator of this revision, explaining the changes.
$node->revision_timestampUnix timestamp showing when current revision was created.
$node->nameUsername of node creator.
$node->pictureUser avatar of the node creator.
$node->cidCID of last comment?
$node->last_comment_timestampTimestamp of last comment (Unix Epoch C).
$node->last_comment_nameName of last comment author
$node->last_comment_uidUID of last comment author.
$node->comment_countNumber of comments made on node.
$node->dataSerialized string of data associated with the node.
$node->rdf_mappingW3C standard to describe structured data. Seehttp://api.drupal.org/api/drupal/modules!rdf!rdf.module/group/rdf/7

透過 Field API 所加入的欄位結構

例如加入名為 foo 的文字欄位,要取出其值可用:

$val = $node->field_foo[LANGUAGE_NONE][0]['value'];


如果覺得這樣不方便,可用 meta wrapper 來包:

$wrapper = entity_metadata_wrapper('node', $node);
$val = $wrapper->field_foo->value();


要用哪一種?  其實都可以,如果只是要讀取某欄的值,先用

drupal_set_message('debug: ' . print_r($node->field_foo, TRUE));


確認該欄的結構後,直接取值就好。

若有多個值要存取,改用 wrapper 才會較有感。


沒有留言: