Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6583277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:23:16+00:00 2026-05-25T16:23:16+00:00

I am building an administration panel for a website and I would like to

  • 0

I am building an administration panel for a website and I would like to change the view called when a 404 exception occurs but only for the admin application. (path: /admin/*)

I have already overdid the error404.html.twig view (at app/Resources/TwigBundle/views/Exception/) for the website.

I thought of the kernel.exception event listener but now I am stuck with two things:

  • Loading another error view only when the route starts with the prefix: /admin/

    $route = $event->getRequest->get('_route')->render()
    //returns NULL
    
  • Calling the $event->container->get('templating')->render() function.

I end up with an infinite loop (blank page) as the script fails.

The only things I’ve got working are:

  • Retrieving the exception code:

    $exception = $event->getException();
    $code = $exception->getCode();
    
  • Creating a new response:

    $response = new Response();
    $event->setResponse($response);
    

Any suggestions on how to achieve this?

[EDIT]

The class:

namespace Cmt\AdminBundle\EventListener;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\TwigBundle\TwigEngine;

class AdminActionListener
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * @var TwigEngine
     */
    protected $templating;


    /**
     * @param ContainerInterface $container
     */
    public function __construct(ContainerInterface $container, TwigEngine $templating){
        // assign value(s)
        $this->container = $container;
        $this->templating = $templating;
    }

    /**
     * 
     * @param GetResponseForExceptionEvent $event
     */
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        // get exception
        $exception = $event->getException();

        // get path
        $path = $event->getRequest()->getPathInfo();

        /*
        * Redirect response to new 404 error view only
        * on path prefix /admin/ 
            */
        }
}

And the services.yml:

services:
    cmt_admin.exception.action_listener:
        class: Cmt\AdminBundle\EventListener\AdminActionListener
        arguments: [@service_container] [@templating]
        tags:
            -   { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:23:17+00:00Added an answer on May 25, 2026 at 4:23 pm

    For some reason, this worked:

    // get exception
    $exception = $event->getException();
    
    // get path
    $path = $event->getRequest()->getPathInfo();
    
    if ($exception->getStatusCode() == 404 && strpos($path, '/admin') === 0){
    
        $templating = $this->container->get('templating');
    
        $response = new Response($templating->render('CmtAdminBundle:Exception:error404.html.twig', array(
            'exception' => $exception
        )));
    
        $event->setResponse($response);
    }
    

    Which is basically what I was doing earlier with a different syntax…

    @dmirkitanov Anyway, thanks for your help !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a web application, and I would like to make certain functions on
I'm building a quite large Flex application as our administration tools and I need
Building a website that has English & Japanese speaking users, with the Japanese users
I am building an administration space in my web application. To do this, I
I'm building a FRAME solution for my CMS . But, before you all start
I am building a website for a customer who may not be very computer
We need to build an administration portal website to support our client/server application. Since
I'm building a java portlet (JSR-168) application and want to define settings, which only
I'm building an application that accepts credit card orders, but does not programatically authorize
I'm building a custom authentication filter class in Grails. It's working, but it bugs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.