在 Twig 中正确显示 photo/image
Correctly display photo/image in Twig
我想在 Symfony2.My 中显示图像而不是文件名 images lives inside web/uploads/images。使用 Symfony 文档提供的以下代码,我可以成功地以表格形式上传文件,并显示它在模板中。
protected function getUploadDir()
{
return 'uploads/images';
}
protected function getUploadRootDir()
{
return __DIR__.'/../../../../web/'.$this->getUploadDir();
}
public function getWebPath()
{
return null === $this->photo ? null : $this->getUploadDir().'/'.$this->photo;
}
public function getAbsolutePath()
{
return null === $this->photo ? null : $this->getUploadRootDir().'/'.$this->photo;
}
所以而不是
<td>{{ entity.photo }}</td>
显示
Photo | beard_1ap68nk-1ap68o8.jpg
在我的模板中,显示这些图像而不是文件名的正确方法是什么?
试试 this.This 应该可以
<td><img src="/uploads/images{{ entity.photo }}" /></td>
我想在 Symfony2.My 中显示图像而不是文件名 images lives inside web/uploads/images。使用 Symfony 文档提供的以下代码,我可以成功地以表格形式上传文件,并显示它在模板中。
protected function getUploadDir()
{
return 'uploads/images';
}
protected function getUploadRootDir()
{
return __DIR__.'/../../../../web/'.$this->getUploadDir();
}
public function getWebPath()
{
return null === $this->photo ? null : $this->getUploadDir().'/'.$this->photo;
}
public function getAbsolutePath()
{
return null === $this->photo ? null : $this->getUploadRootDir().'/'.$this->photo;
}
所以而不是
<td>{{ entity.photo }}</td>
显示
Photo | beard_1ap68nk-1ap68o8.jpg
在我的模板中,显示这些图像而不是文件名的正确方法是什么?
试试 this.This 应该可以
<td><img src="/uploads/images{{ entity.photo }}" /></td>