繁体   English   中英

如何查看存储在数据zf2中的图像

[英]how to view image stored in data zf2

我有一个图像要显示在视图中,当我将它放在 public/assets/img 文件夹中并在视图(.phtml)中写入时,它包含的代码有效:

<img src="/assets/img/logo.jpg"  width="150" height="150" class="img-circle pull-left" alt="<?= $fournisseur->intitule ?>"  />

我想将图像放在 data/img 文件夹中并将其显示在我的视图中,我如何在视图中显示它我尝试使用此代码,删除路径中的数据但没有图像视图:

<img src="/data/img/logo.jpg"  width="150" height="150" class="img-circle pull-left" alt="<?= $fournisseur->intitule ?>"  />

我想为图像创建一个 controller:

public function imageAction()
{
    /** get id by url  **/
 $imageContent = file_get_contents('./data/img/logo.jpg');
    /** set file to reponse   **/
    $response->setContent($imageContent);
    /**  creat header **/
    $response
        ->getHeaders();
    return $response;
}

在视图中:

<img src=<?=$this->url('fourni',array('action' => 'image');?>class="img-rounded" alt="image" width="50" height="50">

我正在寻找做同样的事情......我只是这样解决它:

在我的 phtml 文件中:

<img src="<?php echo $this->basePath() .'/../data/img/logo.jpg';?>">

希望有用。

确保数据文件夹也在公用文件夹内,否则您将需要 go 到目录“./../data/img/”才能访问该图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM