How to display the current picture above the upload field in SonataAdminBundle?

后端 未结 7 2049
广开言路
广开言路 2021-02-01 20:31

I am using SonataAdminBundle (with Doctrine2 ORM) and I have successfully added a file upload feature to my Picture model.

I would like, on the

7条回答
  •  温柔的废话
    2021-02-01 20:40

    you can easily do this on edit page by helpers(FormMapper->setHelps) or option "help" pass on FormMapper

    protected function configureFormFields(FormMapper $formMapper) {
        $options = array('required' => false);
        if (($subject = $this->getSubject()) && $subject->getPhoto()) {
            $path = $subject->getPhotoWebPath();
            $options['help'] = '';
        }
    
        $formMapper
            ->add('title')
            ->add('description')
            ->add('createdAt', null, array('data' => new \DateTime()))
            ->add('photoFile', 'file', $options)
        ;
    }
    

提交回复
热议问题