您好,感谢您一直以来对我的帮助。我在管理员登录时创建了一个登录表单,它显示了所有带有添加、删除、编辑选项的用户列表
我的成功登录和显示用户列表的查看代码是这样的
<a href="<?php echo $view['router']->generate('deleteuser',array('id'=>$id,))?>">Delete</a>
<td><a href="<?php echo $view['router']->generate('edituser',array('id'=>$id))?>">Edit</a></td>
当管理员单击特定的删除选项时,它将在 url 中生成特定用户的 ID,如下所示url:deleteuser?id=6
对于此路由,我有一个带有删除操作的控制器 deleteuser,它再次创建一个视图以确认是否删除用户。即使我单击 no 按钮,我的用户正在删除我的 deleteuser 控制器
class deleteuserController extends Controller
{
public function showAction(Request $request)
{
$request = $this->getRequest();
$register = new users();
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('RepairStoreBundle:users');
$result = $repository->display();
return $this->render('RepairLoginBundle:login:success.html.php',array('result'=>$result,));
}
public function deleteAction(Request $request)
{
$id= $_GET['id'];
$request = $this->getRequest();
$register = new users();
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('RepairStoreBundle:users');
if($request->getMethod() == 'POST')
{
$register = $repository->find($id);
$result = $repository->display();
return $this->render('RepairLoginBundle:login:success.html.php',array('result'=>$result,));
}
return $this->render('RepairLoginBundle:admin:deleteuser.html.php');
}
}
我的routing.yml
文件是
delete:
pattern: /delete
defaults: { _controller:RepairLoginBundle:deleteuser:show}
deleteuser:
pattern: /deleteuser
defaults: { _controller:RepairLoginBundle:deleteuser:delete}
这是我的delete.html.php
<div class="modal-footer">
<a href="<?php echo $view['router']->generate('deleteuser')?>">
<input type="submit" name="Yes" class="btn btn-success" value=Yes /></a>
<a href="<?php echo $view['router']->generate('delete')?>"><input type="submit" name="No" class="btn" data-dismiss="modal" value="No"/></a>
</form>
</div>
即使单击“否”,它也不会生成删除路线,您能告诉我哪里出错了吗?