मेरे पास कई सिम्फनी 3 बंडलों द्वारा रचित एक साधारण वेब ऐप है, जिनके नियंत्रक बेसकंट्रोलर का विस्तार करते हैं। मेरे पास एक AdminBundle भी है। हर नहीं विद्यमान यूआरएल के लिए दिए गए पृष्ठ दिखाने के लिए, मैं काट दिया (और सरल बनाया) मूल ExceptionController.php (TwigBundle से):
<?php
namespace MyApp\AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use MyApp\Controller\BaseController;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
class ExceptionController extends BaseController
{
/**
* Converts an Exception to a Response.
*
* @param Request $request The request
* @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
*
* @return Response
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
$code = $exception->getStatusCode();
return $this->render('MyappAdminBundle:Admin:error.html.twig',
array(
'status_code' => $code,
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
'exception' => $exception,
'logger' => $logger,
'currentContent' => $currentContent,
)
);
}
/**
* @param int $startObLevel
*
* @return string
*/
protected function getAndCleanOutputBuffering($startObLevel)
{
if (ob_get_level() <= $startObLevel) {
return '';
}
Response::closeOutputBuffers($startObLevel + 1, true);
return ob_get_clean();
}
}
मैं के रूप में मैं इसे पसंद किया मेरी त्रुटि टेम्पलेट परिभाषित करते हैं।
मैं
twig:
exception_controller: MyappAdminBundle:Exception:show
ps मुझे यकीन है कि मेरे कोड सुधार किया जा सकता हूँ config.yml भीतर निम्न पंक्ति जोड़ने की जरूरत है, लेकिन यह ठीक काम करता है।
धन्यवाद, घटना श्रोता मुझे लगता है कि जाने का तरीका है, लेकिन $ यह-> templating मान्य नहीं है। मैंने $ event-> templating भी कोशिश की है। मुझे नहीं लगता कि सामान्य नियंत्रक विधियां उपलब्ध हैं। मुझे एक अपरिभाषित संपत्ति मिलती है: सिम्फनी \ घटक \ Http कर्नेल \ Event \ GetResponseForExceptionEvent :: $ templating ... – user2143356
आप सही हैं, सामान्य नियंत्रक विधियां उपलब्ध नहीं हैं क्योंकि वे सेवाओं पर विधि कॉल के लिए उपनाम हैं। आपको ईवेंट विवरण में ईवेंट श्रोता में 'templating' सेवा इंजेक्ट करना चाहिए। –
उस समय मैं यथार्थवादी नहीं था, यह वास्तव में एक टवीग टेम्पलेट सेट करता है, वास्तव में एक पृष्ठ या नियंत्रक नहीं। – user2143356