Symfony 为什么我不能';你不能改变一个小树枝上的css样式吗?

Symfony 为什么我不能';你不能改变一个小树枝上的css样式吗?,symfony,Symfony,我最近开始与symfony合作,但仍然无法处理它的所有错误和问题。我无法修改树枝内部的任何样式!!如果我在css样式文件中使用css代码,或者我使用div的style属性,它就不起作用 这是样式表块: <!-- CSS --> {% block stylesheets %} <link href={{asset("css/bootstrap.min.css")}} rel="stylesheet"> <link href={{asset(

我最近开始与symfony合作,但仍然无法处理它的所有错误和问题。我无法修改树枝内部的任何样式!!如果我在css样式文件中使用css代码,或者我使用div的style属性,它就不起作用
这是样式表块:

  <!-- CSS -->
    {% block stylesheets %}
    <link href={{asset("css/bootstrap.min.css")}} rel="stylesheet">
    <link href={{asset("css/style2.css")}} rel="stylesheet">
    <link href={{asset("css/font-awesome.min.css")}} rel="stylesheet">
    {% endblock %}

{%块样式表%}
{%endblock%}
我想在这里更改css:

 {% if users %}
               <div id="users_table">
                <table style="background-color: #f9f9f9;"
                       class="table table-responsive table-bordered">
                    <tr>
                        <th style="color: #1b6d85"> Matricule </th>
                        <th style="color: #1b6d85"> Mot de passe </th>
                        <th style="color: #1b6d85"> Etat </th>
                        <th style="color: #1b6d85"> Action </th>
                    </tr>
                    {% for user in users %}
                    {% set iduser = user.username %}
                    {% set id = user.username %}
                    <tr><td>{{ user.username }}</td><td>{{ user.password }}</td><td>{% if user.etat==1 %}actif
                            {% elseif user.etat==0%}inactif{% endif %}</td>
                    <td>
                    <button id="activer" class="btn btn-success btn-xs">
                        <a href="{{ path('act', {'iduser': iduser})}}" style="color: #ffffee;text-decoration:none">Activer</a>
                    </button>
                    <button id="desactiver" class="btn btn-danger btn-xs">
                        <a href="{{ path('desact', {'id': id})}}" style="color: #ffffee;text-decoration: none;">Désactiver</a>
                    </button>
                    </td></tr>
                    {% endfor %}
                </table>
               </div>
            {% else %}
                    Aucun utilisateur n'a été trouvé.
            {% endif %}
{%if用户%}
矩阵
路况
埃塔特
行动
{users%%中的用户为%s}
{%set iduser=user.username%}
{%set id=user.username%}
{{user.username}{{user.password}{%if user.etat==1%}actif
{%elseif user.etat==0%}不活动{%endif%}
{%endfor%}
{%else%}
这是一个成功的例子。
{%endif%}

1st-如果每次更改视图文件(.html.twig),则必须清除缓存 对于开发人员:

php bin/console cache:clear
对于prod:

php bin/console cache:clear --env=prod
第二个-检查浏览器中网页的源代码-是资产的好地方()

如果使用引导创建文件使其适应细枝:

# app\config\config.yml

# (...)
form:
    resources:
        - 'YourBundle:Form:form_theme.html.twig'
示例表单_theme.html.twig:

    # YourBundle\Resources\views\Form\form_theme.html.twig
{% spaceless %}
{% block form_start %}
    {% set method = method|upper %}
    {% if method in ["GET", "POST"] %}
        {% set form_method = method %}
    {% else %}
        {% set form_method = "POST" %}
    {% endif %}
    {% set attr = attr|merge({'class': (attr.class|default('form-horizontal'))|trim }) %}
    <form name="{{ form.vars.name }}" method="{{ form_method|lower }}" action="{{ action }}"{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
    {% if form_method != method %}
        <input type="hidden" name="_method" value="{{ method }}" />
    {% endif %}
{% endspaceless %}
{% endblock form_start %}

{% block form_row %}
{% spaceless %}
    <div class="form-group{{ errors|length > 0 ? ' has-error':'' }}">
        {{ form_label(form) }}
        <div class="col-sm-9">
            {{ form_widget(form) }}
            {{ form_errors(form) }}
        </div>
    </div>
{% endspaceless %}
{% endblock form_row %}

{% block form_label %}
{% spaceless %}
    {% if label is not sameas(false) %}
        {% if not compound %}
            {% set label_attr = label_attr|merge({'for': id}) %}
        {% endif %}
        {% if required %}
            {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
        {% endif %}
        {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' col-sm-3 control-label')|trim }) %}
        {% if label is empty %}
            {% set label = name|humanize %}
        {% endif %}
        <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
    {% endif %}
{% endspaceless %}
{% endblock form_label %}

{% block form_widget_simple %}
{% spaceless %}
    {% set type = type|default('text') %}
    {% if type != 'file' %}
        {% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim }) %}
    {% endif %}
    <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %}
{% endblock form_widget_simple %}

{% block textarea_widget %}
{% spaceless %}
    {% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim }) %}
    <textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
{% endspaceless %}
{% endblock textarea_widget %}

{% block choice_widget_collapsed %}
{% spaceless %}
    {% if required and empty_value is none and not empty_value_in_choices %}
        {% set required = false %}
    {% endif %}
    {% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim }) %}
    <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
        {% if empty_value is not none %}
            <option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ empty_value|trans({}, translation_domain) }}</option>
        {% endif %}
        {% if preferred_choices|length > 0 %}
            {% set options = preferred_choices %}
            {{ block('choice_widget_options') }}
            {% if choices|length > 0 and separator is not none %}
                <option disabled="disabled">{{ separator }}</option>
            {% endif %}
        {% endif %}
        {% set options = choices %}
        {{ block('choice_widget_options') }}
    </select>
{% endspaceless %}
{% endblock choice_widget_collapsed %}

{% block choice_widget_expanded %}
{% spaceless %}
    {% for child in form %}
    <div class="checkbox">
        <label>
            {{ form_widget(child) }} {{ child.vars.label }}
        </label>
    </div>
    {% endfor %}
{% endspaceless %}
{% endblock choice_widget_expanded %}

{% block form_errors %}
{% spaceless %}
    {% for error in errors %}
        <span class="help-block">{{ error.message }}</span>
    {% endfor %}
{% endspaceless %}
{% endblock form_errors %}

{% block button_row %}
{% spaceless %}
    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            {{ form_widget(form) }}
        </div>
    </div>
{% endspaceless %}
{% endblock button_row %}

{% block button_widget %}
{% spaceless %}
    {% if label is empty %}
        {% set label = name|humanize %}
    {% endif %}
    {% set attr = attr|merge({'class': (attr.class|default('') ~ ' btn')|trim }) %}
    <button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ label|trans({}, translation_domain) }}</button>
{% endspaceless %}
{% endblock button_widget %}

{% block submit_widget %}
{% spaceless %}
    {% set type = type|default('submit') %}
    {% set attr = attr|merge({'class': (attr.class|default('btn-success'))|trim }) %}
    {{ block('button_widget') }}
{% endspaceless %}
{% endblock submit_widget %}
\YourBundle\Resources\views\Form\Form\u theme.html.twig
{%spaceless%}
{%block form_start%}
{%set method=method | upper%}
{%if方法位于[“GET”,“POST”]%}
{%set form_method=method%}
{%else%}
{%set form_method=“POST”%}
{%endif%}
{%set attr=attr | merge({'class':(attr.class | default('form-horizontal'))| trim})%}
{%if form_method!=method%}
{%endif%}
{%endspaceless%}
{%endblock form_start%}
{%block form_row%}
{%spaceless%}
{{form_标签(form)}
{{form_widget(form)}
{{form_errors(form)}}
{%endspaceless%}
{%endblock form_row%}
{%block form_label%}
{%spaceless%}
{%如果标签不相同(错误)%}
{%如果不是复合%}
{%set label_attr=label_attr|merge({'for':id})%}
{%endif%}
{%如果需要%}
{%set label_attr=label_attr | merge({'class':(label_attr.class | default(“”)~'required')| trim})%}
{%endif%}
{%set label_attr=label_attr | merge({'class':(label_attr.class | default(“”)~'col-sm-3 control label')| trim})%}
{%如果标签为空%}
{%set label=name |人性化%}
{%endif%}
{label | trans({},translation_domain)}
{%endif%}
{%endspaceless%}
{%endblock form_label%}
{%block form_widget_simple%}
{%spaceless%}
{%set type=type | default('text')%}
{%if类型!='文件'%}
{%set attr=attr | merge({'class':(attr.class | default(“”)~'form control')| trim})%}
{%endif%}
{%endspaceless%}
{%endblock form_widget_simple%}
{%block textarea_widget%}
{%spaceless%}
{%set attr=attr | merge({'class':(attr.class | default(“”)~'form control')| trim})%}
{{value}}
{%endspaceless%}
{%endblock textarea_widget%}
{%block choice_widget_collapsed%}
{%spaceless%}
{%if required and empty_value在_choices%}
{%set required=false%}
{%endif%}
{%set attr=attr | merge({'class':(attr.class | default(“”)~'form control')| trim})%}
{%如果空值不是none%}
{{empty_value}trans({},translation_domain)}
{%endif%}
{如果首选|长度>0%}
{%set options=首选选项%}
{{block('choice_widget_options')}
{%如果选项|长度>0且分隔符不是none%}
{{分隔符}}
{%endif%}
{%endif%}
{%set options=choices%}
{{block('choice_widget_options')}
{%endspaceless%}
{%endblock choice_widget_collapsed%}
{%block choice_widget_expanded%}
{%spaceless%}
{表格%中的子项为%1}
{{form_widget(child)}{{child.vars.label}}
{%endfor%}
{%endspaceless%}
{%endblock choice_widget_expanded%}
{%block form_errors%}
{%spaceless%}
{错误%中的错误为%0}
{{error.message}}
{%endfor%}
{%endspaceless%}
{%endblock form_errors%}
{%block button_row%}
{%spaceless%}
{{form_widget(form)}
{%endspaceless%}
{%endblock按钮\行%}
{%block button_widget%}
{%spaceless%}
{%如果标签为空%}
{%set label=name |人性化%}
{%endif%}
{%set attr=attr | merge({'class':(attr.class | default(“”)~'btn')| trim})%}
{label | trans({},translation_domain)}
{%endspaceless%}
{%endblock按钮\小部件%}
{%block submit_widget%}
{%spaceless%}
{%set type=type | default('submit')%}
{%set attr=attr | merge({'class':(attr.class | default('btn-success'))| trim})%}
{{block('button_widget')}
{%endspaceless%}
{%endblock提交\小部件%}

Twig非常强大,与普通PHP模板相比非常简单。无论如何,您必须知道内联样式是一种非常糟糕的做法,因为它会降低页面生成速度。如果这只是出于测试目的,那么“不起作用”是什么意思?这不是一个明确的问题,所以只是一个猜测:您必须将文件复制到web目录,您可以使用cli命令执行此操作:php bin/console assets:install文件位于web文件夹中,也位于Bundle/Resources/public文件夹中。但并不是所有的变化