繁体   English   中英

锂电视图中的嵌入式SVG

[英]Inline SVG in Lithium View

锂的新手总数。

我正在尝试在Lithium View中内联SVG文件。

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

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

在Lithium中,这将在文件寻找位置方面引发一个史诗般的错误:

警告:file_get_contents(images / styleguide / left-arrow.svg):无法打开流://app/resources/tmp/cache/templates/template_styleguide_index.html_17440333_1480885998_1509.php中没有此类文件或目录

由于这个位置,我想知道这样做的“锂方式”是什么(如果有的话)。

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

使用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>

暂无
暂无

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

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