Php MongoDBException:按调用查找无效
我有一个MongodbeException: “按调用包\Document\Property进行查找无效::$fieldName (标准带)” 我不明白这里怎么了。有人能帮我吗 下面是堆栈跟踪: 一,。在第38行的Php MongoDBException:按调用查找无效,php,mongodb,symfony,php-5.6,Php,Mongodb,Symfony,Php 5.6,我有一个MongodbeException: “按调用包\Document\Property进行查找无效::$fieldName (标准带)” 我不明白这里怎么了。有人能帮我吗 下面是堆栈跟踪: 一,。在第38行的vendor/doctrine/mongodb-odm/lib/doctrine/odm/mongodb/MongoDBException.php中 public static function invalidFindByCall($documentName, $fieldName,
vendor/doctrine/mongodb-odm/lib/doctrine/odm/mongodb/MongoDBException.php
中
public static function invalidFindByCall($documentName, $fieldName, $method) {
return new self(sprintf('Invalid find by call %s::$fieldName (%s)', $documentName, $fieldName, $method));
}
vendor/doctrine/mongodb-odm/lib/doctrine/odm/mongodb/DocumentRepository.php中
if ($this->class->hasField($fieldName)) {
return $this->$method(array($fieldName => $arguments[0]));
} else {
throw MongoDBException::invalidFindByCall($this->documentName, $fieldName, $method . $by);
}
在DocumentRepository->\u调用('findByCriteriaWith',array(array('name'=>'ho'))
中的src/Bundle/Controller/PropertyController.php
第286行
else {
criteria['name'] = $name;
$entities = $repository->findByCriteriaWith($criteria);
}
日志消息:
关键请求未捕获PHP异常
条令\ODM\MongoDB\MongoDBException:“通过调用查找无效”
Bundle\Document\Property::$fieldName(criteriaWith)“at”
供应商/doctor/mongodb-odm/lib/doctor/odm/mongodb/MongoDBException.php
第38行上下文:{“异常”:
“对象(条令\ODM\MongoDB\MongoDBException)”}
让我们浏览一下ODM的文档存储库(因为不存在findByCriteriaWith
),并突出显示感兴趣的部分
首先我们看到
if (strpos($method, 'findBy') === 0) {
$by = substr($method, 6, strlen($method));
$method = 'findBy';
}
您的方法名称以“findBy”开头,因此我们将进入此块,稍后我们将使用$method='findBy'
和$by='CriteriaWith'
,稍后$by
将被简化,因为这是字段/属性名称的标准,并留给我们$fieldName='CriteriaWith'
。现在我们看到的下一件事是$this->class->hasField($fieldName)
检查您得到的异常,因为您的类没有criteriaWith
字段
汇总$repository->findBySomething($value)
相当于$repository->findBy(['something'=>$value])
并在DooDocument中不存在字段时引发异常。看起来您的DocumentRepository.php类没有名为“criteriaWith”的字段,该字段似乎是必须的