php - Symfony2 Entity was not found - FIle Upload in a relationship -


i have entity have manytoone file entity.

my problem when try delete.

this how create:

/**  * creates new catalogo entity.  *  * @route("/create", name="catalogo_create")  * @method("post")  * @template("bwsbajacupcakesbundle:catalogo:new.html.twig")  */ public function createaction(request $request) {     $entity  = new catalogo();     $file = new archivo();      $form = $this->createform(new catalogotype(), $entity);     $form->bind($request);      $file_form = false;      if($form['file']->getdata()){         $file_form = $form['file'];         //unset($form['file']);     }     if ($form->isvalid()) {         $em = $this->getdoctrine()->getmanager();         $em->persist($entity);          if($file_form){                 $tipoimagen = $em->getrepository('bwsbajacupcakesbundle:tipoarchivo')->find(1);                 $file->setfile($file_form->getdata());                 $file->setprincipal(true);                 $file->settipo($tipoimagen);                 $file->setfechacaptura(date_create(date("y-m-d h:i:s")));                 $file->upload();                    $em->persist($file);                 $entity->setimagen($file);         }          $em->flush();          return $this->redirect($this->generateurl('catalogo_show', array('id' => $entity->getid())));     }      return array(         'entity' => $entity,         'form'   => $form->createview(),     ); } 

this how delete:

/**      * deletes catalogo entity.      *      * @route("/{id}/delete", name="catalogo_delete")      * @method("post")      */     public function deleteaction(request $request, $id)     {            $form = $this->createdeleteform($id);         $form->bind($request);      if ($form->isvalid()) {         $em = $this->getdoctrine()->getmanager();         $entity = $em->getrepository('bwsbajacupcakesbundle:catalogo')->find($id);          if (!$entity) {             throw $this->createnotfoundexception('unable find catalogo entity.');         }          $em->remove($entity);         $em->flush();     }      return $this->redirect($this->generateurl('catalogo')); } 

this relationship:

/**  * @orm\manytoone(targetentity="bws\bajacupcakesbundle\entity\archivo", cascade={"all"})  * @orm\joincolumn(name="imagen_id", referencedcolumnname="id")  */ private $imagen; 

i dont it, did in other symfony applications , never had issue.

thanks in advance help.

cheers

although have answer in comment, i'd tought i'd give code in case (based on cookbook document entity):

/**  * pre remove upload  *  * @orm\preremove()  */ public function preremoveupload() {     $this->temp = $this->getabsolutepath(); }  /**  * remove upload  *  * @orm\postremove()  */ public function removeupload() {     if ($this->temp) {         unlink($this->temp);     } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -