Yii2: How to use backend web folders files in frontend

◇◆丶佛笑我妖孽 提交于 2019-12-11 19:16:21

问题


I have many images in backends web folder, I want to use those images in frontend how to get those files?

I need to display 1 (first) image which path is saved in database like Img1.jpg;img2.jpg;

    <?php
      foreach (explode(';',rtrim($row['images'],';'),1) as $key_img => $value_img)
 {
  ?>

<?php echo  Html::img('@backend/web'.'/'.$value_img);?>                  

<?php
 }
?>

回答1:


<?= \yii\helpers\Html::img('@backend/web/images/your-image.jpg') ?>

The src parameter, containing the backend alias, will be processed by Url::to()

Check the docs for details on Html::img().




回答2:


Simply try:

<?= \yii\helpers\Html::img( Yii::getAlias('@backend'). '/web/images/your-image.jpg') ?>


来源:https://stackoverflow.com/questions/36264463/yii2-how-to-use-backend-web-folders-files-in-frontend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!