dtqie02844 2017-07-11 15:21 采纳率: 0%
浏览 72

Symfony 3.3 - 链接到bootstrap.min.css

After investing quite some time on this problem I still cannot get this to work. In my base.html.twig file I link to the bootstrap.min.css file, located at css/bootstrap.min.css inside the web directory, as follows:

{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}" />
{% endblock %}

I then extend the base.html.twig file in my template files, when I navigate to any of these files I get the following error message:

> Request URL:http://example/css/bootstrap.min.css
Request Method:GET
Status Code:404 Not Found

I'm at a loss as to what I'm doing wrong here! Any help would be appreciated.

base.html.twig file:

<!DOCTYPE html>
<html lang="en">
    <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 %}


    <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>
          <a class="navbar-brand" href="#">Todo List</a>
        <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>
        </div><!--/.nav-collapse -->

    <div class="container">
      <div class="row">
        <div class="col-md-12">
          {% block body %}{% endblock %}
    </div><!-- /.container -->
    {% block javascripts %}
    {% endblock %}

The index.html.twig file:

{% extends 'base.html.twig' %}

{% block body %}
{% endblock %}

My server config:

<VirtualHost *:80>
DocumentRoot "/xampp/htdocs/symfony/todolist/web/app_dev.php"
ServerName todolist
  • 写回答

1条回答 默认 最新

  • dongshan2004 2017-07-11 16:40

    So your Apache config seems to be what prevents you from accessing those files. Use the following version instead:

    <VirtualHost *:80>
        ServerName todolist
        DocumentRoot /xampp/htdocs/symfony/todolist/web
        <Directory /xampp/htdocs/symfony/todolist/web>
            AllowOverride All
            Order Allow,Deny
            Allow from All

    Check out this page for more info: https://symfony.com/doc/current/setup/web_server_configuration.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥60 爬虫登录易班工作站后台失败(相关搜索:登录页面)
  • ¥15 机器人关节变量求解问题
  • ¥15 ros小车启动launch文件报错
  • ¥15 vs2015到期想登陆但是登陆不上
  • ¥20 Intellij实现web登录界面
  • ¥15 IPQ5018制作烧录固件,boot运行失败(操作系统-linux)(相关搜索:操作系统)(相关搜索:操作系统)
  • ¥20 icefall在librispeech基础上加入个人数据集
  • ¥30 keepalive高可用故障运维配置询问
  • ¥15 求帮助!国家电网内网u盘突然识别不出来了。
  • ¥15 matlab语音变速变调同时实现