[英]Inline SVG in Lithium View
Total newbie to Lithium. 锂的新手总数。
I'm trying to inline an SVG file in a Lithium View. 我正在尝试在Lithium View中内联SVG文件。
In previous PHP Frameworks I would just do the following: 在以前的PHP框架中,我将执行以下操作:
<?php echo file_get_contents('images/styleguide/left-arrow.svg'); ?>
In Lithium this will throw a pretty epic error with regards to where it's looking for the file: 在Lithium中,这将在文件寻找位置方面引发一个史诗般的错误:
Warning: file_get_contents(images/styleguide/left-arrow.svg): failed to open stream: No such file or directory in //app/resources/tmp/cache/templates/template_styleguide_index.html_17440333_1480885998_1509.php
警告:file_get_contents(images / styleguide / left-arrow.svg):无法打开流://app/resources/tmp/cache/templates/template_styleguide_index.html_17440333_1480885998_1509.php中没有此类文件或目录
Because of this location I'm wondering what the "lithium way" of doing this would be (if at all). 由于这个位置,我想知道这样做的“锂方式”是什么(如果有的话)。
I found a solution to this (please add answers if there is a better solution). 我找到了解决方案(如果有更好的解决方案,请添加答案)。
Use the Media class to get the root or your static files: 使用Media类获取根目录或您的静态文件:
use lithium\net\http\Media;
$webrootPath = Media::webroot(true);
Using this you can get the file contents: 使用此方法,您可以获取文件内容:
$watchRound = file_get_contents($webrootPath.'/images/styleguide/watch-round.svg');
Then inline it: 然后内联它:
<button class="toolbar__btn js-styleguide-viewport-watch-round">
<?php echo $watchRound; ?>
</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.