Другой способ обработки ошибок ошибки использования сеанса, как
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