TYPO3 延迟加载错误
TYPO3 Lazy Loading Error
我收到错误
Argument 1 passed to
[...]\FrontendUserRepository::findMasterByVkbur()
must be an instance of [...]\MyModel,
instance of TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
given, called in [...]\MyController.php on line 123
为什么参数仍然是 "LazyLoadingProxy" 而不是 "MyModel"?
这是 MyController.php 中的第 123 行:
$frontendUsers = $this->frontendUserRepository->findMasterByVkbur($this->feuser->getVkbur());
这是 "vkbur" 对象:
/**
* @var \MyVendor\MyExt\Domain\Model\MyModel
* @lazy
*/
protected $vkbur = null;
当"using"之前的对象时,例如与...
\TYPO3\CMS\Core\Utility\DebugUtility::debug($this->feuser->getVkbur());
...我没有在第 123 行收到此错误。
这是一个主题,但被放弃了。
解决方案似乎是你评论说的:
if ($this->feuser->getVkbur() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
$vkbur = $this->feuser->getVkbur()->_loadRealInstance();
} else {
$vkbur = $this->feuser->getVkbur();
}
$frontendUsers = $this->frontendUserRepository->findMasterByVkbur(vkbur);
最好的解决方案似乎是检查 getter 方法中变量的类型:
/**
* @return \MyVendor\MyExt\Domain\Model\MyModel $vkbur
*/
public function getVkbur() {
if($this->vkbur instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
$this->vkbur->_loadRealInstance();
}
return $this->vkbur;
}
在某些情况下似乎仍然需要如上所示检查 LazyLoadingProxy。但这不应该像这里解释的那样解决吗? https://wiki.typo3.org/Enhanced_Lazy_Loading
我收到错误
Argument 1 passed to [...]\FrontendUserRepository::findMasterByVkbur() must be an instance of [...]\MyModel, instance of TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy given, called in [...]\MyController.php on line 123
为什么参数仍然是 "LazyLoadingProxy" 而不是 "MyModel"?
这是 MyController.php 中的第 123 行:
$frontendUsers = $this->frontendUserRepository->findMasterByVkbur($this->feuser->getVkbur());
这是 "vkbur" 对象:
/**
* @var \MyVendor\MyExt\Domain\Model\MyModel
* @lazy
*/
protected $vkbur = null;
当"using"之前的对象时,例如与...
\TYPO3\CMS\Core\Utility\DebugUtility::debug($this->feuser->getVkbur());
...我没有在第 123 行收到此错误。
这是一个主题,但被放弃了。
解决方案似乎是你评论说的:
if ($this->feuser->getVkbur() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
$vkbur = $this->feuser->getVkbur()->_loadRealInstance();
} else {
$vkbur = $this->feuser->getVkbur();
}
$frontendUsers = $this->frontendUserRepository->findMasterByVkbur(vkbur);
最好的解决方案似乎是检查 getter 方法中变量的类型:
/**
* @return \MyVendor\MyExt\Domain\Model\MyModel $vkbur
*/
public function getVkbur() {
if($this->vkbur instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
$this->vkbur->_loadRealInstance();
}
return $this->vkbur;
}
在某些情况下似乎仍然需要如上所示检查 LazyLoadingProxy。但这不应该像这里解释的那样解决吗? https://wiki.typo3.org/Enhanced_Lazy_Loading