问题描述
我有一个图像要在视图中显示,当我将它放在 public/assets/img 文件夹中并写入 view(.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 ?>" />
我想为图像创建一个控制器:
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">
解决方法
确保数据文件夹也在公共文件夹内,否则您需要进入目录“./../data/img/”才能访问该图像。