简体   繁体   中英

Retrieving an image to a view from a directory in Symfony2

我遵循了 symfony2 食谱中提供的上传教程,我现在的问题是如何检索文件并对应于数据库中的记录...谢谢

If you followed this tutorial, you will notice that your object has a getWebPath() function. You can use this function to get a path that you can use on your web site to create a link to this document. For example, in twig:

<a href="{{document.getWebPath()}}">Document</a>

I have been able to implement both the upload and also editing of the uploaded file with reference to the entity but cannot be able to delete.Here is the method am using for delete in the controller.

public function deleteimageAction($id)
{
    $form = $this->createDeleteForm($id);
    $request = $this->getRequest();

    $form->bindRequest($request);

    if ($form->isValid()) 
    {
        $em = $this->getDoctrine()->getEntityManager();
        $entity = $em->getRepository('AcmeDemoBundle:Document')->find($id);

        if (!$entity) 
        {
            throw $this->createNotFoundException('Unable to find Document entity.');
        }
        $entity->removeUpload(); 

        //$em->remove($entity);
        $em->persist($entity);
        $em->flush();

    }

    return $this->redirect($this->generateUrl('viewimages'));
} 

Any help will be appreciated...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM