我们正在将 4.5 扩展迁移到 7.2。有一种特殊情况很奇怪。尝试获取 findOneByUid 会出现“没有给出用于检索数据映射的类名”。错误。
通过另一个对象访问并使用 DebuggerUtility,它允许我们导航到失败的对象,我们可以看到,objectType 为 NULL。
有哪里可以搜索的线索吗?所有其他对象都可以通过 findOneByUid 访问。
您将如何继续查找问题?
添加以下几行解决了问题...知道如何避免这种情况吗?
public function __construct() {
$this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$this->objectType = \TYPO3\CMS\Core\Utility\ClassNamingUtility::translateRepositoryNameToModelName($this->getRepositoryClassName());
}
如果存储库的构造函数已在子类中被重写而不调用父构造函数,则对象类型只能是
null
。 parent::__construct();
您应该使用方法
initializeObject
,而不是使用构造函数,该方法在构造函数之后调用,并且可以安全地重写。
我有同样的问题(TYPO3 11.5)。
致命错误:未捕获类型错误:传递给 TYPO3\CMS\Extbase\Persistence\Generic\Query::setType() 的参数 1 必须是字符串类型,给定 null
我收到错误是因为我在模型存储库中添加了函数 __construct() 并且没有调用parent::__construct(),这使得 $this->objectType = NULL
解决方案:
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
public function __construct(
ObjectManagerInterface $objectManager,
ConnectionPool $connectionPool
){
parent::__construct( $objectManager );
$this->connectionPool = $connectionPool;
}