2017-05-18 14 views
0

私はSymfony 2.8とSonata ORMとSonata Adminバンドルを使用しています。Sonata AdminのShow Actionに画像を表示するには?

私はthisを使用して編集アクションで画像を表示しますが、正常に動作します。

私はショーのアクションで画像を表示したい、との命令が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', array(
      'prefix' => '/bundles/acme/images/', 
      'width' => 75, 
      'height' => 75, 
     )) 
    ; 
} 

希望:あなたはまた、画像の接頭辞または固定幅と高さを使用することができます

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

関連する問題