7.x - Node object core structure (不含 fields)
$node->nid | Node ID. |
$node->vid | The revision ID of the current version of this node. |
$node->type | Type of node (e.g. book, page, forum), which is also the entity bundle. |
$node->language | The default language for this node. |
$node->title | Page (or, more accurately, node) title. |
$node->uid | User ID of node creator. |
$node->status | unpublished/published (NODE_NOT_PUBLISHED | NODE_PUBLISHED). |
$node->created | UNIX timestamp of node creation date. |
$node->changed | UNIX timestamp of last time node was changed. |
$node->comment | Whether comments are allowed on this node (COMMENT_NODE_HIDDEN | COMMENT_NODE_CLOSED | COMMENT_NODE_OPEN) |
$node->promote | Promoted to front page (NODE_NOT_PROMOTED | NODE_PROMOTED). |
$node->sticky | Sticky (NODE_NOT_STICKY | NODE_STICKY). |
$node->tnid | The node ID of the translation source (or parent, if node is a translation). |
$node->translate | Does the translation need to be updated (0|1)? |
$node->revision_uid | The user ID of the user who created the current revision. |
$node->body | Array. 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->log | Message left by the creator of this revision, explaining the changes. |
$node->revision_timestamp | Unix timestamp showing when current revision was created. |
$node->name | Username of node creator. |
$node->picture | User avatar of the node creator. |
$node->cid | CID of last comment? |
$node->last_comment_timestamp | Timestamp of last comment (Unix Epoch C). |
$node->last_comment_name | Name of last comment author |
$node->last_comment_uid | UID of last comment author. |
$node->comment_count | Number of comments made on node. |
$node->data | Serialized string of data associated with the node. |
$node->rdf_mapping | W3C 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 才會較有感。
沒有留言:
張貼留言