public function indexAction()
{
// retrieve the object from database
$product = ...;
if (!$product) {
throw $this->createNotFoundException('The product does not exist');
}
return $this->render(...);
}
В документации есть короткая информация:
"Метод createNotFoundException() создает специальный объект NotFoundHttpException, который в конечном итоге вызывает 404 HTTP-ответ внутри Symfony."
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException
В моих сценариях я сделал это так:
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException
/**
* @Route("/{urlSlug}", name="test_member")
* @Template()
*/
public function showAction($urlSlug) {
$test = $this->getDoctrine()->.....
if(!$test) {
throw new NotFoundHttpException('Sorry not existing!');
}
return array(
'test' => $test
);
}