大家好,我是 Laravel 的新手,这是我在 Laravel 中做的第一个项目,我无法在我的 View 中链接我的 Assets (CSS 和 Js)文件。我做了一项研究,发现我是否会使用 {{URL::asset('assets/plugins/bootstrap/css/bootstrap.min.css')}}
在 Laravel 5.1 中它将起作用。当它只是一个链接时我确实成功了,但是当我添加其他链接时..
<link rel="stylesheet" href="{{URL::asset('assets/plugins/animate.css')}}">
<link rel="stylesheet" href="{{URL::asset('assets/plugins/line-icons/line-icons.css')}}">
<link rel="stylesheet" href="{{URL::asset('assets/plugins/parallax-slider/css/parallax-slider.css')}}">
<link rel="stylesheet" href="{{URL::asset('assets/css/custom.css')}}">
服务器拒绝访问 Assets 文件夹 Access forbidden!
中的所有文件。
我的 .htaccess 文件代码是..
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
问题是 .htaccess 文件是否有问题,为什么当我放置一个 Assets 链接时它接受了? 或者链接文件的正确方法是什么? 我正在使用 XAMPP 作为我的本地服务器。 *伙计,我昨天刚学了 Laravel,所以对我放轻松...提前致谢
最佳答案
你可以使用 laravel blade 模板方法
{!! HTML::style('css/style.css') !!}
{!! HTML::script('js/script.js') !!}
注意:您应该将 css 文件添加到 public 文件夹中,这意味着在我的示例中它将类似于 public/css
文件夹。
同样也将应用于 jquery 文件。
如果您使用在线链接,您也可以添加以下方式
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
否则
<link rel="stylesheet" href="{{ URL::asset('css/style.css') }}" />
<script type="text/javascript" src="{{ URL::asset('js/jquery.js') }}"></script>
关于php - 如何在 Laravel 5.1 项目中链接外部 CSS 和脚本( Assets ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32197160/