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工作它是一个嵌入管理