Php Entity\EntityStorageInterface::loadMultiple()需要给定数组| null,数组| int
有人知道我为什么会犯这个错误吗?代码做了应该做的,但当我与Phing核对时,我得到: 方法“Drupal\Core\Entity\EntityStorageInterface::load multiple()”的参数#1$id需要数组| null,数组| int给定Php Entity\EntityStorageInterface::loadMultiple()需要给定数组| null,数组| int,php,drupal,drupal-8,Php,Drupal,Drupal 8,有人知道我为什么会犯这个错误吗?代码做了应该做的,但当我与Phing核对时,我得到: 方法“Drupal\Core\Entity\EntityStorageInterface::load multiple()”的参数#1$id需要数组| null,数组| int给定 因为方法Drupal\Core\Entity\Query\QueryInterface::execute()可以返回一个整数或数组,而Drupal\Core\Entity\EntityStorageInterface::loadMu
因为方法
Drupal\Core\Entity\Query\QueryInterface::execute()
可以返回一个整数或数组
,而Drupal\Core\Entity\EntityStorageInterface::loadMultiple()
只接受数组
或空
作为参数,所以Phing如上警告您
但您不必担心这一点,因为方法execute()
在调用之前的count()
时只返回int
。对于您的代码,它总是返回一个数组
您是否尝试获取已执行查询的结果?:)您好,您能详细说明一下,这是什么意思吗?当您在查询结束时调用execute()
方法时,如果执行成功与否,您会得到一个布尔值。为了用结果填充变量,您需要获取该查询上的数据,这意味着您需要调用可用的获取方法之一,如fetch()
,fetchAll()
,fetchAllAssoc()
。。等等。任何一个都可以工作,但请记住,其中一个返回stdClass,另一个返回关联的数组,因此在使用数据之前一定要检查数据。
$comment_ids = $this->entityTypeManager
->getStorage('comment')
->getQuery('AND')
->condition('entity_id', $entity->id())
->condition('entity_type', 'node')
->sort('cid', 'DESC')
->execute();
$comments = $this->entityTypeManager
->getStorage('comment')
->loadMultiple($comment_ids);