Twig 使用「;如果;“条件”;至于;
我想把我的symfony 4应用程序投入生产,一切都很顺利,但在一些页面上我有一个错误500,我可以找到问题的来源,但我不知道如何解决它Twig 使用「;如果;“条件”;至于;,twig,symfony4,Twig,Symfony4,我想把我的symfony 4应用程序投入生产,一切都很顺利,但在一些页面上我有一个错误500,我可以找到问题的来源,但我不知道如何解决它 {% for articleUps in articleUp if articleUps.statut == "épinglé" %} <div class="article"> <img src="{{ asset('assets/avatar/')~a
{% for articleUps in articleUp if articleUps.statut == "épinglé" %}
<div class="article">
<img src="{{ asset('assets/avatar/')~articleUps.user.image }}"
class="card-img-top photo rounded-circle">
<i class="fas fa-thumbtack"></i><a href="{{ path('forum_articles', {'id': articleUps.id , 'slug': articleUps.slug }) }}">{{ articleUps.sujet }}</a><br>
<strong>Crée le {{articleUps.createdAt|localizeddate('none', 'none', 'fr', null, 'EEEE d MMMM Y') }} • par<a href="{{ path('app_profil', {'username': articleUps.user.username}) }} ">{{ articleUps.user.username }}</a></strong>
{% if is_granted('ROLE_ADMIN') %}
<a href="{{ path('article_edit', {'id': articleUps.id}) }}" class="lien">editer</a>
{% endif %}
</div>
<hr>
{% endfor %}
我如何才能确保生产中不再有bug
我改变了我的状况,以下是在开发中仍然有效但在生产中不起作用的消息:
{% for articleUps in articleUp %}
{% if articleUps.statut == "épinglé" %}
<div class="article">
<img src="{{ asset('assets/avatar/')~articleUps.user.image }}"
class="card-img-top photo rounded-circle">
<i class="fas fa-thumbtack"></i><a href="{{ path('forum_articles', {'id': articleUps.id , 'slug': articleUps.slug }) }}">{{ articleUps.sujet }}</a><br>
<strong>Crée le {{articleUps.createdAt|localizeddate('none', 'none', 'fr', null, 'EEEE d MMMM Y') }} • par<a href="{{ path('app_profil', {'username': articleUps.user.username}) }} ">{{ articleUps.user.username }}</a></strong>
{% if is_granted('ROLE_ADMIN') %}
<a href="{{ path('article_edit', {'id': articleUps.id}) }}" class="lien">editer</a>
{% endif %}
</div>
<hr>
{% endif %}
{% endfor %}
{%用于articleUp%中的articleUps}
{%if articleUps.statut==“épinglé”%}
Crée le{{articleUps.createdAt|localizeddate('none','none','fr',null','eee d MMMM Y')}•par
{%if_被授予('ROLE_ADMIN')%}
{%endif%}
{%endif%}
{%endfor%}
这只是一个警告-Twig v2没有弃用for
语句中的if
,但它仍然正常工作,直到您升级到Twig的下一个主要版本。Symfony和相关工具非常适合这种不推荐
至于确保您在生产中没有其他bug,日志(在开发和生产中)将显示哪些地方存在其他的不推荐问题或问题,启用更多日志记录非常有用,最好是使用“祈祷”错误处理程序。这将保留可用于请求的所有日志记录,但只有在出现错误时才将它们全部写入日志文件
至于在问题存在之前发现问题——测试。单元测试、功能和集成
从Twig 2.10开始,改用过滤器过滤器,或者在for主体内使用if条件(如果您的条件取决于循环内更新的变量,并且您没有使用循环变量)。
-
没有别的办法解决我的问题吗?只有这个错误,我有Twig V 2.7I更改了我的条件,这里有一条消息仍然适用于开发,但不适用于生产。确实,从现在开始,您必须将
if
移动到for
的内部-它应该也适用于您的生产平台。请参阅,确保已正确清理缓存
{% for articleUps in articleUp %}
{% if articleUps.statut == "épinglé" %}
<div class="article">
<img src="{{ asset('assets/avatar/')~articleUps.user.image }}"
class="card-img-top photo rounded-circle">
<i class="fas fa-thumbtack"></i><a href="{{ path('forum_articles', {'id': articleUps.id , 'slug': articleUps.slug }) }}">{{ articleUps.sujet }}</a><br>
<strong>Crée le {{articleUps.createdAt|localizeddate('none', 'none', 'fr', null, 'EEEE d MMMM Y') }} • par<a href="{{ path('app_profil', {'username': articleUps.user.username}) }} ">{{ articleUps.user.username }}</a></strong>
{% if is_granted('ROLE_ADMIN') %}
<a href="{{ path('article_edit', {'id': articleUps.id}) }}" class="lien">editer</a>
{% endif %}
</div>
<hr>
{% endif %}
{% endfor %}