Lithium View中的内联SVG

时间:2016-12-04 21:20:31

标签: php lithium

锂的新手。

我试图在Lithium View中内联一个SVG文件。

在之前的PHP框架中,我将执行以下操作:

<?php echo file_get_contents('images/styleguide/left-arrow.svg'); ?>

在锂电池中,这会给它寻找文件的位置带来一个相当大的错误:

  

警告:file_get_contents(images / styleguide / left-arrow.svg):失败   打开流:没有这样的文件或目录   //app/resources/tmp/cache/templates/template_styleguide_index.html_17440333_1480885998_1509.php

由于这个位置,我想知道&#34;锂的方式&#34;这样做(如果有的话)。

1 个答案:

答案 0 :(得分:1)

我找到了解决方法(如果有更好的解决方案,请添加答案)。

使用Media类获取根文件或静态文件:

use lithium\net\http\Media;

$webrootPath = Media::webroot(true);

使用此功能,您可以获取文件内容:

$watchRound = file_get_contents($webrootPath.'/images/styleguide/watch-round.svg');

然后内联:

<button class="toolbar__btn js-styleguide-viewport-watch-round">
  <?php echo $watchRound; ?>
</button>