【问题标题】:Is there a helper method for getting the absolute path to storage directory of masonite?是否有获取 masonite 存储目录的绝对路径的辅助方法?
【发布时间】:2019-09-21 11:48:46
【问题描述】:

我需要能够获取控制器中的绝对路径和存储路径的视图。对于我的 Masonite 应用程序中的不同静态资产,一些存储路径是不同的。

我该怎么做?

【问题讨论】:

    标签: masonite


    【解决方案1】:

    Masonite 对此有帮助。您可以像这样在视图中直接使用它:

    假设这样的配置:

    DRIVERS = {
        'disk: {
            'location': '/storage/directory'
        }
    }
    

    你可以这样做:

    <img src="{{ static('disk', 'profile.jpg')">
    

    这将产生类似/storage/directory/profile.jpg的输出

    现在假设你有一个这样的配置文件:

    DRIVERS = {
        'disk: {
            'location': {
                'storage': '/storage/directory',
                'uploads': '/storage/uploads',
            }
        }
    }
    

    你可以稍微修改你的静态助手:

    <img src="{{ static('disk.uploads', 'profile.jpg')">
    

    您还可以通过from masonite.helpers import static在视图之外使用帮助器

    【讨论】:

      猜你喜欢
      • 2014-11-12
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 2023-04-05
      • 2012-04-06
      • 2014-01-26
      • 1970-01-01
      • 2015-12-18
      相关资源
      最近更新 更多