I have read the the other questions concerning this issue but have not come across a solution as of yet.
I get the following error message:
The class 'Doctrine\ORM\EntityManager' was not found in the chain configured >namespaces ZfcUser\Entity, Common\Entity, Employment\Entity, Intern\Entity, >Team\Entity, PurchaseRequest\Entity.
I have a HolidayEntity, HolidayController, HolidayService.
Adding a holiday works, but when I try to remove a holiday the error pops up. I pass the holiday id from to controller to the service, which then fetches the associated object and runs the doctrine 2 removeEntity command.
I am unsure as to how to tackle the problem at the moment.
Controller code:
public function deleteAction()
{
$holidayId = $this->params()->fromRoute('id', 0);
try {
$this->getServiceLocator()->get('holidayService')->removeHoliday($holidayId);
} catch (Exception $e) {
$this->flashMessenger()->addErrorMessage($e->getMessage() . '<br>' . $e->getTraceAsString());
}
return $this->redirect()->toRoute('holiday/list');
}
Service Code:
public function removeHoliday($holidayId)
{
try{
$holiday = $this->findOneHolidayById($holidayId);
$this->removeEntity($holiday);
} catch (Exception $e) {
var_dump($e);
}
}
protected function removeEntity($entity)
{
$this->getEntityManager()->remove($entity);
$this->getEntityManager()->flush();
}
The code breaks in the "$this->getEntityManager()->remove($entity)" method.
The error you are getting relates to Doctrine not being able to find an Entity called Doctrine\ORM\EntityManager
, which is clearly wrong.
My guess is that somewhere (perhaps in the getEntityManager()
method) you are passing an instance of the entity manager to the entity manager.
For example
$entityManager = new EntityManager();
$entity = new EntityManager();
$entityManager->remove($entity);