php 来自http://www.codeexpertz.com/blog/drupal/drupal-8-accessing-node-values-and-properties-loading

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 来自http://www.codeexpertz.com/blog/drupal/drupal-8-accessing-node-values-and-properties-loading相关的知识,希望对你有一定的参考价值。

Syntax:
use Drupal\node\Entity\Node;
$node = Node::load(NID);
print_r($node);
Node Properties:
$id = $node->id();
$title = $node->title->value;
$vid = $node->vid->value;
Node field values
$field1 = $node->get('FIELD_1')->getValue());
$field2 = $node->get('FIELD_2')->getValue());
Examples:
Get Node object:
use Drupal\node\Entity\Node;
$node = Node::load(NID);
print_r($node); // Node Object.
Node Content Type:
use Drupal\node\Entity\Node;
$node = Node::load(NID);
print $node->bundle(); // Content type of Node.
Node NID:
use Drupal\node\Entity\Node;
$node = Node::load(NID);
print $node->id(); // Node Id.
Node Properties(Revision Id, Title, Author Id, Timestamp, etc..):
use Drupal\node\Entity\Node;
$node = Node::load(NID);
print $node->vid->value; // Revison Id.
print $node->title->value; // Node Id.
print $node->uid->value; // Author Id.
print $node->created->value; // Created Timestamp.
Node Field values:
use Drupal\node\Entity\Node;
$node = Node::load(NID);
$tags = $node->get('field_tag')->getValue());
print $tags;
// Output.
Array
(
  [0] => Array
    (
      [target_id] => 1
    )
 
)

以上是关于php 来自http://www.codeexpertz.com/blog/drupal/drupal-8-accessing-node-values-and-properties-loading的主要内容,如果未能解决你的问题,请参考以下文章

PHP 来自php脚本的Linux shell命令

PHP 来自PHP的HTTP POST,没有cURL

如何使用 PHP 显示来自 Amazon S3 的图像?

用来自 php 的数据填充 flash 中的数组

PHP需要来自***目录的文件

php 剥离MS Word HTML。来自php.net