Symfony2 : customize error pages for different bundles

前端 未结 2 2022
别跟我提以往
别跟我提以往 2021-02-04 08:48

I have several bundles and I\'d like to know if it is possible to customize for each bundle their own error pages.

I read the cookbook and the examples

2条回答
  •  梦谈多话
    2021-02-04 09:44

    The listener itself would have to detect that - I'm not aware of any way to specify a listener for a single bundle.

    getException();
        $namespace = new \ReflectionObject( $event->getController() )->getNamespaceName();
    
        switch ( $namespace )
        {
          case 'Acme\\DemoBundle':
            // do whatever with $exception here
            break;
          case 'Some\\OtherBundle':
            // do whatever with $exception here
            break;
          case 'Your\\MainBundle':
            // do whatever with $exception here
            break;
          default;
            // default
        }
      }
    }
    

    And register it

    //services.yml
    kernel.listener.yourlistener:
      class: Your\MainBundle\YourExceptionListener
      tags:
        - { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
    

提交回复
热议问题