- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有图像的实体,我正在使用 EasyAdmin 3.0 和 VichUploader 1.14 在管理控制台中上传图像。我的问题是我无法在管理控制台中显示图像。我怎样才能做到这一点 ?这是我的实体:
class Question
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"question"})
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"question"})
*/
private $title;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="stand_image", fileNameProperty="imageName", size="imageSize")
*
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", nullable=true)
*
* @var string|null
*/
private $imageName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var int|null
*/
private $imageSize;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTimeInterface|null
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"question"})
*/
private $answer;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"question"})
*/
private $explanation;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"question"})
*/
private $level;
/**
* @ORM\OneToMany(targetEntity=Answer::class, mappedBy="question")
* @Groups({"question"})
*/
private $answers;
/**
* @ORM\ManyToOne(targetEntity=Game::class, inversedBy="questions")
* @Groups({"question"})
*/
private $game;
/**
* @ORM\OneToMany(targetEntity=Proposal::class, mappedBy="question")
* @Groups({"question"})
*/
private $proposals;
public function __construct()
{
$this->answers = new ArrayCollection();
$this->proposals = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function getAnswer(): ?string
{
return $this->answer;
}
public function setAnswer(string $answer): self
{
$this->answer = $answer;
return $this;
}
public function getExplanation(): ?string
{
return $this->explanation;
}
public function setExplanation(?string $explanation): self
{
$this->explanation = $explanation;
return $this;
}
public function getLevel(): ?int
{
return $this->level;
}
public function setLevel(?int $level): self
{
$this->level = $level;
return $this;
}
/**
* @return Collection|Answer[]
*/
public function getAnswers(): Collection
{
return $this->answers;
}
public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers[] = $answer;
$answer->setQuestion($this);
}
return $this;
}
public function removeAnswer(Answer $answer): self
{
if ($this->answers->contains($answer)) {
$this->answers->removeElement($answer);
// set the owning side to null (unless already changed)
if ($answer->getQuestion() === $this) {
$answer->setQuestion(null);
}
}
return $this;
}
public function getGame(): ?Game
{
return $this->game;
}
public function setGame(?Game $game): self
{
$this->game = $game;
return $this;
}
/**
* @return Collection|Proposal[]
*/
public function getProposals(): Collection
{
return $this->proposals;
}
public function addProposal(Proposal $proposal): self
{
if (!$this->proposals->contains($proposal)) {
$this->proposals[] = $proposal;
$proposal->setQuestion($this);
}
return $this;
}
public function removeProposal(Proposal $proposal): self
{
if ($this->proposals->contains($proposal)) {
$this->proposals->removeElement($proposal);
// set the owning side to null (unless already changed)
if ($proposal->getQuestion() === $this) {
$proposal->setQuestion(null);
}
}
return $this;
}
public function __toString()
{
return "{$this->title}";
}
}
这是我的 vich_uploader.yaml 文件:
vich_uploader:
db_driver: orm
mappings:
question_image:
uri_prefix: /images/questions
upload_destination: '%kernel.project_dir%/public/images/questions'
namer: Vich\UploaderBundle\Naming\OrignameNamer
这是我的 EasyAdmin CRUD Controller :
class QuestionCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Question::class;
}
public function configureCrud(Crud $crud): Crud
{
return $crud
// Les labels utilisés pour faire référence à l'entité dans les titres, les boutons, etc.
->setEntityLabelInSingular('question')
->setEntityLabelInPlural('questions')
// Le titre visible en haut de la page et le contenu de l'élément <title>
// Cela peut inclure ces différents placeholders : %entity_id%, %entity_label_singular%, %entity_label_plural%
->setPageTitle('index', 'Liste des %entity_label_plural%')
->setPageTitle('new', 'Créer une %entity_label_singular%')
->setPageTitle('edit', 'Modifier la %entity_label_singular% <small>(#%entity_id%)</small>')
// Définit le tri initial appliqué à la liste
// (l'utilisateur peut ensuite modifier ce tri en cliquant sur les colonnes de la table)
->setDefaultSort(['id' => 'ASC'])
;
}
public function configureActions(Actions $actions): Actions
{
return $actions
->update(Crud::PAGE_INDEX, Action::NEW, function (Action $action) {
return $action->setLabel('Ajouter une %entity_label_singular%');
})
->update(Crud::PAGE_INDEX, Action::EDIT, function (Action $action) {
return $action->setLabel('Modifier');
})
->update(Crud::PAGE_INDEX, Action::DELETE, function (Action $action) {
return $action->setLabel('Supprimer');
})
->update(Crud::PAGE_NEW, Action::SAVE_AND_RETURN, function (Action $action) {
return $action->setLabel('Créer');
})
->update(Crud::PAGE_NEW, Action::SAVE_AND_ADD_ANOTHER, function (Action $action) {
return $action->setLabel('Créer et ajouter une autre %entity_label_singular%');
})
->update(Crud::PAGE_EDIT, Action::SAVE_AND_RETURN, function (Action $action) {
return $action->setLabel('Sauvegarder les changements');
})
->update(Crud::PAGE_EDIT, Action::SAVE_AND_CONTINUE, function (Action $action) {
return $action->setLabel('Sauvegarder et continuer à modifier');
})
->update(Crud::PAGE_DETAIL, Action::DELETE, function (Action $action) {
return $action->setLabel('Supprimer');
})
->update(Crud::PAGE_DETAIL, Action::INDEX, function (Action $action) {
return $action->setLabel('Retour à la liste');
})
->update(Crud::PAGE_DETAIL, Action::EDIT, function (Action $action) {
return $action->setLabel('Modifier');
})
;
}
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id', 'Id')->hideOnForm(),
TextField::new('title', 'Intitulé'),
ImageField::new('imageFile', 'Image')
->setFormType(VichImageType::class)
->setBasePath('/public/images/questions'),
TextField::new('answer', 'Réponse'),
TextField::new('explanation', 'Explications'),
IntegerField::new('level', 'Niveau'),
AssociationField::new('game', 'Jeu'),
];
}
}
Here's the result in my admin console. What I'd want is that the image appears instead of null.
最佳答案
您必须仅在表单页面上显示 imageFile(使用 ->onlyOnForms()),在索引页面上您必须显示 imageName(使用 onlyOnIndex())并设置与 VichUploader 配置中相同的路径(/images/questions) .
看这个例子:
public function configureFields(string $pageName): iterable
{
return [
ImageField::new('imageName', 'Image')
->onlyOnIndex()
->setBasePath('/images/questions'),
ImageField::new('imageFile', 'Image')
->onlyOnForms()
->setFormType(VichImageType::class)
];
}
关于image - 如何使用 EasyAdmin 3.0 和 VichUploader 在管理控制台中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63724845/
我会尽可能地解释我正在做的事情,以获得最好的可能的建议/解决方案。这一切都是在 java 中完成的。 我的客户有一个基于 SWING 的桌面应用程序,它将使用 WebStart 加载。我被指派为用户帐
看来这个page包含 Azure CLI 支持的与 Azure API 管理相关的所有功能。但它没有展示如何使用 Azure CLI 管理用户、产品、证书、订阅和 API 等实体。 Azure CLI
我设置了一个 Hadoop 1.2.x 版本,双节点集群。第一节点(NameNode、Jobtracker)和第二节点(Secondary NameNode、Datanode、TaskTracker)
对于内容驱动的网站,设计好坏的关键是关系型数据库。在这个教程中,我们已经使用了MySQL关系型数据库管理系统(RDBMS)建立了我们的数据库。对于网站的开发者来说,MySQL是一个较受欢迎的选择,这
在尝试运行MariaDB之前,首先确定其当前状态,运行或关闭。 有三个选项用于启动和停止MariaDB – 运行mysqld(MariaDB脚本)。 运行mysqld_safe启动脚本。
我在管理界面中遇到 StackedInlines 前缀的问题。我会尝试发布所有必要的代码。 models.py(简要) ##### Base classes class BaseItem(models
我是新来的。到目前为止,我一直在使用 MVC 模型并使用基本的 session 管理模型,即在 session 中存储一个 token 并检查每个请求。 我正在尝试对lift做同样的事情,但我的 se
我在 win 服务中使用 NHiberante。有时我得到 System.ObjectDisposedException: Session is closed! Object name: 'ISess
我正在尝试使用 HtmlUnit 登录 Facebook 页面并查看其 HTML 内容。我正在尝试通过 HtmlUnit 填写登录凭据,但在单击提交按钮时我没有看到正在执行的 session 。 在
我正在为一个相当大的项目开发一个带有 reactjs 的前端,该项目有两个主要接口(interface)。主站点的前端和管理员的前端。 我应该将它们开发为两个不同的项目还是 reactjs 中的一个项
短版 我有一个使用插件基础结构的应用程序。插件具有可配置的属性,可帮助它们了解如何完成工作。插件按配置文件分组以定义如何完成任务,配置文件存储在由 DataContractSerializer 序列化
如何管理 iPhone 应用程序中的用户 session ?我在应用程序的第一页上从用户那里获取了用户名和密码。用户可以随时注销。如何像其他 Web 应用程序一样在 iPhone 应用程序中存储 se
我正在使用 Azure API 管理,其中包含第三方论坛 (Discourse) 的链接。 api管理提供的默认登录系统用于注册用户。我想知道是否可以对 api 管理和论坛使用单点登录,这样用户就不必
我正在使用 Wordpress 建立一个网站,并且我想利用它的 session 。但我没有找到任何插件,甚至文档。在我开始破解之前有什么建议或引用吗? 注意:我问的是 WP 是否以及如何使用标准 PH
我已阅读《Azure in Action》一书中的以下内容:“在 Windows Azure 中,状态服务器或进程外 session 状态提供程序,不支持” 谁能告诉我为什么不支持这个。他们在书中没有
我有一个内联表单集,我想排除一些模型对象在表单集中显示。 例如。模型 B 具有模型 A 的外键,因此它是 1:n(A 对象有许多 B 对象)关系。现在在 A 管理编辑页面上,我已经获得了 B 的内联。
我正在开发一个基于 session 的项目。我在想,与银行类似,我会创建一张支票并为用户提供阻止 session 超时的能力。 我正在考虑创建一个 setInterval 来检查需要身份验证的空白页面
我正在为一位拥有 Magento 商店的客户工作。里面塞满了产品,但这些产品的名称有点乱。他并没有坚持一种命名约定,而是多年来使用了不同的约定。因此,每当他使用“管理”->“管理产品”部分中的“名称”
我使用大约十几个 XSLT 文件来提供大量输出格式。目前,用户必须知道导出的文件格式的扩展名,例如RTF、HTML、TXT。 我还想使用参数来允许更多选项。如果我可以将元数据嵌入 XSL 文件本身,那
我已阅读《Azure in Action》一书中的以下内容:“在 Windows Azure 中,状态服务器或进程外 session 状态提供程序,不支持” 谁能告诉我为什么不支持这个。他们在书中没有
我是一名优秀的程序员,十分优秀!