deleteAction() with Doctrine

Home Forums Learn ZF2 deleteAction() with Doctrine

This topic contains 1 reply, has 2 voices, and was last updated by  Slavey Karadzhov 4 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #299

    Hi, i’ve been tried to delete one entity with the code bellow:

    $id = $this->params(‘id’);
    if(!$id) {
    return $this->redirect()->toRoute(‘user/default’, array(
    ‘controller’ => ‘account’,
    ‘action’ => ‘view’,

    $entityManager = $this->serviceLocator->get(‘entity-manager’);
    $userEntity = $this->serviceLocator->get(‘user-entity’);

    But it shows the message and don’t remove the entity from database:
    A detached entity was found during removed User\Model\Entity\User@0000000036df71400000000077cf16f7


    Slavey Karadzhov

    Hi Daniel,
    Replace the line:

    with that one:
    $userEntity = $entityManager->find(get_class($userEntity), $id);

    that should work and give you better error reporting.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.