php 从uri获取节点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 从uri获取节点相关的知识,希望对你有一定的参考价值。

$params = \Drupal\Core\Url::fromUserInput($path)->getRouteParameters();
if (isset($params['node'])) {
  $node = \Drupal\node\Entity\Node::load($params['node']);
}


// or

$node = \Drupal::routeMatch()->getParameter('node');
if ($node) {
  // You can get nid and anything else you need from the node object.
  $nid = $node->id();
}

以上是关于php 从uri获取节点的主要内容,如果未能解决你的问题,请参考以下文章