2017-05-18 17 views
0

我正在使用Symphony 2.8和Sonata管理软件包与Sonata ORM。如何在Sonata Admin的Show Action中显示图像?

我使用this在Edit动作中显示图像,它工作正常。

但是我想在展会的行动来显示图像,并说明不会为ImageAdmin

protected function configureShowFields(ShowMapper $showMapper) 
{ 
    if($this->hasParentFieldDescription()) { // this Admin is embedded 
     // $getter will be something like 'getlogoImage' 
     $getter = 'get' . $this->getParentFieldDescription()->getFieldName(); 

     // get hold of the parent object 
     $parent = $this->getParentFieldDescription()->getAdmin()->getSubject(); 
     if ($parent) { 
      $image = $parent->$getter(); 
     } else { 
      $image = null; 
     } 
    } else { 
     $image = $this->getSubject(); 
    } 

    // use $fileFieldOptions so we can add other options to the field 
    $fileFieldOptions = array('required' => false); 
    if ($image && ($webPath = $image->getWebPath())) { 
     // add a 'help' option containing the preview's img tag 
     $fileFieldOptions['help'] = '<img src="'.$webPath.'" class="admin-preview" />'; 
    } 

    $showMapper->add('file', 'file', $fileFieldOptions); 
} 

内configureShowFields工作它是一个嵌入管理

回答

0

你可以有一个看起来这捆绑:SonataExtraAdminBundle

您将能够在showMapper上使用'图像'类型。

protected function configureListFields(ListMapper $listMapper) 
{ 
    $listMapper 
     ... 
     ->add('picture', 'image') 
    ; 
} 

您也可以使用图像前缀或一个固定的宽度和高度:

protected function configureListFields(ListMapper $listMapper) 
{ 
    $listMapper 
     ... 
     ->add('picture', 'image', array(
      'prefix' => '/bundles/acme/images/', 
      'width' => 75, 
      'height' => 75, 
     )) 
    ; 
} 

希望这有助于

相关问题