簡體   English   中英

在渲染模板期間拋出異常(路由“delete_User”的“參數”salt“必須匹配”[^/]++“

[英]An exception has been thrown during the rendering of a template (“Parameter ”salt“ for route ”delete_User“ must match ”[^/]++"

我會創建一個方法來刪除一些在表中分類的用戶這是我的方法刪除

public function deletetAction(User $user)
{
    if (!$user) {
        throw $this->createNotFoundException('No user found');
    }

    $em = $this->getDoctrine()->getEntityManager();
    $em->remove($user);
    $em->flush();

    return $this->redirectToRoute('index_User');
}

我在我的觀點中稱這個方法為 index.html.twig

<tbody>
                 {% for user in useres %}
                    <tr>

                  <td> {{user.username}}  </td>
                  <td> {{user.email}}  </td>
                  <td> {{user.date(user.LastLogin)}}</td> 
                   <td> {{user.enabled}}  </td>
                   <td class="center hidden-400">        
                       <a href="{{ path('delete_User', {'salt':user.salt }) }}"class="glyphicon glyphicon-pencil">delete </a>

                                    </td>

                  <td>{{user.roles[0]}}</td>
                                </tr>
                {% endfor %}
</tbody>

但是當我執行路由索引時,會發布此錯誤

可能,您的字段salt的某些值在數據庫中為空。 因此,您應該在呈現鏈接之前進行檢查。

{% if user.salt|length %}
    <a href="{{ path('delete_User', {
        'salt': user.salt
    }) }}" class="glyphicon glyphicon-pencil">delete</a>
{% endif %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM