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

后端 未结 7 2136
广开言路
广开言路 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:47

    There is an easy way - but you will see the picture below the upload button. SonataAdmin lets put raw HTML into the ‘help’ option for any given form field. You can use this functionality to embed an image tag:

    protected function configureFormFields(FormMapper $formMapper) {
    
        $object = $this->getSubject();
    
        $container = $this->getConfigurationPool()->getContainer();
    
        $fullPath =     $container->get('request')->getBasePath().'/'.$object->getWebPath();
    
    
        $formMapper->add('file', 'file', array('help' => is_file($object->getAbsolutePath() . $object->getPlanPath()) ? '' : 'Picture is not avialable')
    
    }
    

提交回复
热议问题