php - 在渲染模板期间引发了异常(“路由“delete_User”的“参数“salt”必须匹配“[^/]++”
问题描述
我会创建一个方法来删除一些在表中分类的用户这是我的方法删除
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 %}
推荐阅读
- python - 将多列与另一列进行比较时立即选择更小/更大的值
- r - 多列汇总
- java - 将类的对象存储为循环内的 HashMap 的值
- ios - 加载视图控制器后,模糊视图背景变为不透明
- phpstorm - PhpStorm 协议处理程序直接从无法在 Mac 上打开文件的 URL 打开文件
- c# - Asp.net 样板中的 Elsa 工作流集成
- c++ - C++17 找到函数的确切参数并传递给模板函数
- c# - 在 C# .Net Core 中管理增量计数器的最佳方法
- php - 如何添加送货电话号码 paypal order v2 api
- python - 添加字母不起作用 - 请让我知道我哪里出错了