2015-11-03 87 views
1
$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;每个变量后,我得到的结果,直到年底,只有当我删除它,它给我的错误。什么是解决方案?调用一个成员函数上的空ZF2学说ORM 2

+0

也许,你多次执行这个命令,'exit()'会在错误发生之前停止脚本。在'$ class = $ objectManager-> find [...]'后添加一个'if($ class === null){/ *在这里添加调试信息*/die();}'。 –

+0

它崩溃了,但如果我做print_r($ class); exit;相反,我得到一个正常的结果 – f0unix

回答

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(); 

就像我在我的评论说,也许代码运行过程中出现多次。

+0

我编辑了我的回应更多的调试信息。有了这个,你可以得到造成麻烦的对象的ID并解决它;) –

相关问题