簡體   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