简体   繁体   中英

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

i would to create a methode to delete some user who classified in table this is my methodedelete

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');
}

and i call this methode in my views like this 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>

but when i execute the route index this error is posted

Probably, some values for your field salt are empty in the database. So, you should make a check before rendering a link.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM