$section = $objectManager->find('OEC\Entity\Section', $sectionId );
$class = $objectManager->find('OEC\Entity\Classes', $section->getClassId() );
$cycle = $objectManager->find('OEC\Entity\Cycle', $class->getCycleId() );
$branch = $objectManager->find('OEC\Entity\Branch', $cycle->getBranchId() );
$sectionArr = $class->getClassName()." ".$section->getSectionName()." - ". $branch->getBranchName()." ".$cycle->getCycleName();
$objectManager->close();
我收到Call to a member function getCycleId() on null
,但如果我在每个变量之后print_r($variable);exit;
我得到一个结果直到结束,只有当我删除它时它才会给我错误。什么可以解决方案?
答案 0 :(得分:0)
尝试使用以下内容进行调试:
$section = $objectManager->find('OEC\Entity\Section', $sectionId );
$class = $objectManager->find('OEC\Entity\Classes', $section->getClassId() );
if ($class === null) {
/* add debug info here*/
var_dump('ID of class was '.$section->getClassId());
var_dump('ID of section was '.$sectionId);
var_dump((new \Exception())->getTraceAsString());
die();
}
$cycle = $objectManager->find('OEC\Entity\Cycle', $class->getCycleId() );
$branch = $objectManager->find('OEC\Entity\Branch', $cycle->getBranchId() );
$sectionArr = $class->getClassName()." ".$section->getSectionName()." - ". $branch->getBranchName()." ".$cycle->getCycleName();
$objectManager->close();
就像我在评论中所说的那样,代码可能会多次运行。