try {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('product')->find($id);
if (!$entity) {
$this->get('session')->setFlash('warning', 'Unable to find Product.');
}
$em->remove($entity);
$em->flush();
$this->get('session')->setFlash('success', 'Product Detail has been deleted.');
return $this->redirect($this->generateUrl('admin_products'));
} catch (\Doctrine\DBAL\DBALException $e) {
$this->get('session')->setFlash(
'warning', 'This Product cannot be deleted!'
);
return $this->redirect($this->getRequest()->headers->get('referer'));
}
}
추천하고 주어진 코드 아래에 나뭇 가지 템플릿 사용에 대한 오류 처리를 사용 세션 오류에 대한 또 다른 방법.
{% if app.session.hasFlash('success') %}
<div class="alert alert-success">
{{ app.session.flash('success') }}
</div>
{% endif %}
{% if app.session.hasFlash('warning') %}
<div class="alert alert-error">
{{ app.session.flash('warning') }}
</div>
{% endif %}
컨트롤 작업에서이 기능을 사용하지 않는 이유는 무엇입니까? – pbenard