2014-09-25 2 views
0

클릭시 데이터베이스에서 행을 삭제해야합니다. 이메일이있는 데이터베이스가 있습니다. 그리고 데이터베이스에서 전자 메일로 각 입력 근처에 단추를 생성하고이를 삭제하려면 클릭 동작이 필요합니다.Symfony 2. 클릭시 엔티티 삭제

{% for inc in Incmejl %} 
         <input type="text" value="{{ inc.getEmail() }}" > 
        {% endfor %} 

엔티티 이름 : 보고서. 뷰

<a href="{{ path('my_delete_route', { 'id': email.id } }}">delete</a> 

이에, 예를 들어

:

답변

2

그래서 각 이메일은 DB에 ID를 가지고, 그래서 당신이 원하는 무엇을이 매개 변수 ID로 경로를 호출하는 버튼을 만드는 것입니다 경로 my_delete_route는

$repository = $this->getDoctrine()->getManager()->getRepository('AcmeMyBundle:Entity'); 
$email = $repository->find($id); 
$em = $this->getDoctrine()->getManager(); 
$em->remove($email); 
$em->flush(); 

경로 모양을 컨트롤러 DeleteAction ($ id를) 호출

my_delete_route: 
    path:  whatever/{id} 
    defaults: { _controller: AcmeMyBundle:MyController:Delete } 

희망이 있습니다.

+1

나는이게 그것입니다 :) Thanks a lot \ – Cre3k