laravel 如何在 Lumen 中执行 {{ asset('/css/app.css') }} ?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30250112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:33:46  来源:igfitidea点击:

How to do {{ asset('/css/app.css') }} in Lumen?

laravelassetsbladelumen

提问by prograhammer

In Lumen, I can do this in my blade template:

在 Lumen 中,我可以在我的刀片模板中执行此操作:

{{ url('/css/app.css') }}

In Laravel I could do

在 Laravel 我可以做

{{ asset('/css/app.css') }}

Is the url helper all I have to work with in Lumen?

我必须在 Lumen 中使用 url 助手吗?

采纳答案by Hieu Le

Have look at Lumen UrlGenerator source code, the Lumen framework supports just urland routehelpers. Of course, you can write the assethelper if you want.

看看Lumen UrlGenerator 源代码,Lumen 框架支持 justurlroutehelpers。当然,asset如果您愿意,您可以编写帮助程序。

回答by Murwa

Had the same problem, moving from laravel to lumen. As @hieu-le says, I made an asset helper as below.

有同样的问题,从 Laravel 移动到 lumen。正如@hieu-le 所说,我制作了一个资产助手,如下所示。

if (!function_exists('urlGenerator')) {
    /**
     * @return \Laravel\Lumen\Routing\UrlGenerator
     */
    function urlGenerator() {
        return new \Laravel\Lumen\Routing\UrlGenerator(app());
    }
}

if (!function_exists('asset')) {
    /**
     * @param $path
     * @param bool $secured
     *
     * @return string
     */
    function asset($path, $secured = false) {
        return urlGenerator()->asset($path, $secured);
    }
}