【问题标题】:laravel 5.1 css and js files are not readinglaravel 5.1 css 和 js 文件未读取
【发布时间】:2016-01-19 16:59:21
【问题描述】:

我已将资产文件夹复制到公共文件夹并使用

调用了我的 css 文件
<link href="{{!! asset('assets/global/plugins/font-awesome/css/font-awesome.min.css') !!}}" rel="stylesheet" type="text/css" />


<link href="{{ asset('assets/global/plugins/font-awesome/css/font-awesome.min.css') }}" rel="stylesheet" type="text/css" />

但是当我打开本地主机查看我的应用程序时,css 不起作用,当我使用检查元素检查 css 时,它会显示此错误

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Object not found!</title>
<link rev="made" href="mailto:postmaster@localhost" />
<style type="text/css"><!--/*--><![CDATA[/*><!--*/ 
    body { color: #000000; background-color: #FFFFFF; }
    a:link { color: #0000CC; }
    p, address {margin-left: 3em;}
    span {font-size: smaller;}
/*]]>*/--></style>
</head>

<body>
<h1>Object not found!</h1>
<p>


    The requested URL was not found on this server.



    The link on the
    <a href="http://localhost:7777/laravel/resources/views/login.blade.php">referring
    page</a> seems to be wrong or outdated. Please inform the author of
    <a href="http://localhost:7777/laravel/resources/views/login.blade.php">that page</a>
    about the error.



</p>
<p>
If you think this is a server error, please contact
the <a href="mailto:postmaster@localhost">webmaster</a>.

</p>

<h2>Error 404</h2>
<address>
  <a href="/">localhost</a><br />
  <span>Apache/2.4.16 (Win32) OpenSSL/1.0.1p PHP/5.6.12</span>
</address>
</body>
</html>

【问题讨论】:

  • 我用{{URL::asset('/path/to/css')}}
  • 我使用 laravel 5.1,这正是我在默认模板中使用的:&lt;link rel="stylesheet" href="{{URL::asset('css/core.css')}}"&gt; 没有授予正斜杠,但对我来说很好。
  • 我已经尝试了所有方法,但它根本不起作用:(
  • 您确定您的文件位于 public/assets/global/plugins/font-awesome/css/ 中吗?您在 config/app.php 中正确设置了您的应用程序 url 吗?
  • 我没有检查我的 app.php 如何解决这个问题?提前非常感谢你

标签: php css laravel-5


【解决方案1】:

首先,您将所有 css 和 js 文件放入公共文件夹中。 即,wamp->www->您的项目文件夹->公共。

然后在编码部分简单地使用下面提到的技术。

<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>

 <link rel="stylesheet" type="text/css" href="../css/jquery.datetimepicker.css"/>

<script type="text/javascript" src="../select/select2.min.js"></script>
<script type="text/javascript" src="../select/select2.js"></script>

<link href="../select/select2.css" rel="stylesheet">

【讨论】:

    【解决方案2】:

    在资产 url 的开头添加一个斜杠:

    <link href="{{!!asset('/assets/global/plugins/font-awesome/css/font-awesome.min.css') !!}}" rel="stylesheet" type="text/css" />  
    <link href="{{ asset('/assets/global/plugins/font-awesome/css/font-awesome.min.css') }}" rel="stylesheet" type="text/css" />
    

    【讨论】:

      猜你喜欢
      • 2019-08-14
      • 1970-01-01
      • 2019-07-18
      • 2020-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 2011-06-26
      相关资源
      最近更新 更多