이미 개체와 함께 유지되는 null을 유지하는 데 문제가 있습니다.개체를 Null 값으로 바꾸기 Symfony2의 양식 작성기 사용
다음과 같은 오류가 발생합니다.
Catchable Fatal Error: Argument 1 passed to MyProject\EntityBundle\Entity\Requirements::setReplacedEmployee() must be an instance of MyProject\EntityBundle\Entity\Employee, null given, called in /var/www/MyProject/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /var/www/MyProject/src/MyProject/EntityBundle/Entity/Requirements.php line 384
처음에는 null/object 일 수있는 replacedEmployee 개체를 저장합니다. 하지만 나중에 내가 편집하는 동안 null로 개체를 대체하면 위의 오류가 throw됩니다.
아래는 컨트롤러의 코드입니다.
try {
if ($request->request->get('save') === 'Save') {
$form->bindRequest($request); // this is the line which throws the above error
if ($form->isValid()) {
$requirementObj->setUpdatedAt(new \DateTime('now'));
$em->flush();
$request->request->set('requirementId', $requirementId);
return $this->displayAction($request);
}
}
}
이것은 엔티티 파일 인 Requirements.php의 콘텐츠입니다.
/**
* @var replacedEmployee
*
* @ORM\ManyToOne(cascade={"persist"},targetEntity="Employee")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="replaced_employee_id",referencedColumnName="id",onDelete="CASCADE")
* })
*/
private $replacedEmployee;
/**
* Set replacedEmployee
*
* @param MyProject\EntityBundle\Entity\Employee $replacedEmployee
*/
public function setReplacedEmployee(\MyProject\EntityBundle\Entity\Employee $replacedEmployee)
{
$this->replacedEmployee = $replacedEmployee;
}
/**
* Get replacedEmployee
*
* @return MyProject\EntityBundle\Entity\Employee
*/
public function getReplacedEmployee()
{
return $this->replacedEmployee;
}
누구든지이 문제에 대한 해결책을 제안 할 수 있습니다. 사전에
감사합니다.
코드를 추가 할 수 있습니까 – Baba
묻는대로 코드를 추가했습니다 –
Requirements.php에서'Requirements :: setReplacedEmployee()'를 어디에서 호출 했습니까? – Baba