我看过了,据我所知,捆绑中不可能有错误页面。它必须是一个站点范围内的站点app/Resources/views/Exception/error404.html.twig
但是,您可以通过利用 HttpFoundation 组件返回自定义响应
<?php
namespace Acme\WhateverBundle\Controller;
//...
use Symfony\Component\HttpFoundation\Response;
class MyController extends Controller
{
//...
public function takeAction()
{
//..
if ($notFound) {
$twig = $this->container->get('templating');
$content = $twig->render('AcmeAnotherBundle:Exception:error404.html.twig');
return new Response($content, 404, array('Content-Type', 'text/html'));
}
// ...
return $this->render('AcmeWhateverBundle:Default:index.html.twig');
}
}