【问题标题】:Inline SVG in Lithium ViewLithium 视图中的内联 SVG
【发布时间】:2016-12-04 21:20:31
【问题描述】:

锂的新手。

我正在尝试在 Lithium 视图中内联 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

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

【问题讨论】:

    标签: php lithium


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-20
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 2013-05-14
      • 1970-01-01
      • 2016-08-05
      相关资源
      最近更新 更多