Symfony 2 | Form exception when modifying an object that has a file(picture) field

前端 未结 3 1363
鱼传尺愫
鱼传尺愫 2021-02-01 06:51

I\'m using Symfony2. I have an entity Post that has a title and a picture field.

My problem : Everything is fine when I create a post, I have my picture e

3条回答
  •  一生所求
    2021-02-01 07:22

    I would recommend you to read the documentation of file upload with Symfony and Doctrine How to handle File Uploads with Doctrine and a strong recommendation to the part Lifecycle callbacks

    In a brief you usually in the form use the 'file' variable (see documentation), you can put a different label through the options, then in your 'picture' field, you just store the name of the file, because when you need the src file you can just call getWebpath() method.

    ->add('file', 'file', array('label' => 'Post Picture' )
    );
    

    to call in your twig template

    
    

提交回复
热议问题