在这个问题投入了相当长的一段时间之后,我仍然无法让它发挥作用。在我的base.html.twig文件中,我链接到bootstrap.min.css文件,该文件位于web目录中的css / bootstrap.min.css,如下所示:
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}" />
{% endblock %}
然后我在我的模板文件中扩展base.html.twig文件,当我导航到这些文件中的任何一个时,我收到以下错误消息:
> Request URL:http://example/css/bootstrap.min.css
Request Method:GET
Status Code:404 Not Found
我不知道我在这里做错了什么!任何帮助将不胜感激。
base.html.twig文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>{% block title %}Welcome!{% endblock %}</title>
<!-- Bootstrap core CSS -->
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}" />
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
{% endblock %}
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Todo List</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/">Home</a></li>
<li><a href="/todo/create">Add todo</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-12">
{% block body %}{% endblock %}
</div>
</div>
</div><!-- /.container -->
{% block javascripts %}
{% endblock %}
</body>
</html>
index.html.twig文件:
{% extends 'base.html.twig' %}
{% block body %}
/INDEX
{% endblock %}
我的服务器配置:
<VirtualHost *:80>
DocumentRoot "/xampp/htdocs/symfony/todolist/web/app_dev.php"
ServerName todolist
</VirtualHost>
答案 0 :(得分:0)
因此,您的Apache配置似乎阻止您访问这些文件。请改用以下版本:
<VirtualHost *:80>
ServerName todolist
DocumentRoot /xampp/htdocs/symfony/todolist/web
<Directory /xampp/htdocs/symfony/todolist/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
</VirtualHost>
请查看此页面以获取更多信息:https://symfony.com/doc/current/setup/web_server_configuration.html