简体   繁体   English

如何在 Lumen 中将 css 文件链接到我的 html

[英]How to link css files to my html in Lumen

I have just begun learning lumen and can't seem to find the answer to this simple question.我刚刚开始学习流明,似乎无法找到这个简单问题的答案。 This is my current <head> :这是我目前的<head>

   <head>
    <title>Sharp notes!</title>
    <link rel="stylesheet" type="text/css" href="/assets/css/main.css">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
    </head>

This causes the following error:这会导致以下错误:

[Sat Jun 17 20:13:09 2017] 127.0.0.1:56950 [200]: /
[Sat Jun 17 20:13:09 2017] 127.0.0.1:56952 [404]: /assets/css/main.css - No such file or directory

Please help!请帮忙!

You should put the css files in your public directory.您应该将 css 文件放在您的公共目录中。

myApp/public/css/main.css

Then the asset helper should resolve the path correctly然后资产助手应该正确解析路径

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

Further explanation here:进一步的解释在这里:

https://laracasts.com/discuss/channels/general-discussion/asset-vs-url https://laracasts.com/discuss/channels/general-discussion/asset-vs-url

Your assets (css, js, images, etc.) need to be placed in the application's public directory.您的资产(css、js、图像等)需要放在应用程序的公共目录中。

也许它可以帮助你尝试这个

<link rel="stylesheet" type="text/css" href="{{ URL::asset('resources/assets/css/main.css') }}">

The solution : you need to use url('') ,解决方案:您需要使用url('')

Because Lumen does not provide the asset helper function you may want to use url eg因为 Lumen 不提供资产辅助功能,您可能需要使用 url 例如

The url function generates a fully qualified URL to the given path: Blade. url 函数为给定的路径生成一个完全限定的 URL:Blade。 More informations ir : Laravel Helpers url()更多信息 ir : Laravel Helpers url()

HOW TO :如何 :

With Blade :带刀片:

<link rel="stylesheet" href="{{ url('/assets/css/main.css') }}">

With PHP :使用 PHP :

<link rel="stylesheet" href="<?php url('/assets/css/main.css') ?>">

if you want you can create your own asset helper function of course, have a look here:如果您愿意,当然可以创建自己的资产助手功能,请看这里:

https://laracasts.com/discuss/channels/lumen/extend-helper-functions-to-lumen?page=0 https://laracasts.com/discuss/channels/lumen/extend-helper-functions-to-lumen?page=0

or

How to do {{ asset('/css/app.css') }} in Lumen? 如何在 Lumen 中执行 {{ asset('/css/app.css') }}?

You can simply put your assets folder (containing img, libs, js and styles) into public folder & do the needful like like this.您可以简单地将您的资产文件夹(包含 img、libs、js 和样式)放入公共文件夹并像这样执行需要的操作。 <img src="assets/img/visa.PNG">

In laravel lumen you don't have to define the public path .在laravel lumen 中,您不必定义公共路径。 Put your assets into public folder and rest will automatically tracked.将您的资产放入公共文件夹,其余的将自动跟踪。 For more information visit https://lumen.laravel.com有关更多信息,请访问https://lumen.laravel.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM