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 9129401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:44:18+00:00 2026-06-17T07:44:18+00:00

currently I’m working with Symfony2 and it is an awesome framework. I worked with

  • 0

currently I’m working with Symfony2 and it is an awesome framework.

I worked with SpringMVC and it has the concept of “interceptor” which catches requests to any “controller” and allows to make, for example, checks too know if user is logged.

Is there any annotation of router way to do something similar with Symfony2.

Thanks in advance.

  • 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-06-17T07:44:20+00:00Added an answer on June 17, 2026 at 7:44 am

    You can attach event listeners to respond to a framework event. Take a look at:

    http://symfony.com/doc/current/cookbook/service_container/event_listener.html

    There are a number of events you can subscribe to, all of them available on the docs:

    http://api.symfony.com/2.1/Symfony/Component/HttpKernel/KernelEvents.html

    Probably you are looking for the REQUEST event, it should look something like:

    <?php
    
    namespace Acme\DemoBundle\Listener;
    
    use Symfony\Component\DependencyInjection\ContainerInterface;
    use Symfony\Component\HttpKernel\Event\GetResponseEvent;
    
    class Listener
    {
        /**
         * @var \Symfony\Component\DependencyInjection\ContainerInterface
         */
        private $router;
        private $service_container;
    
        public function __construct(\Symfony\Component\Routing\Router $router, $service_container) {
            $this->router = $router;
            $this->service_container = $service_container;
        }
    
        public function onKernelRequest(GetResponseEvent $event) {
             // DO STUFF
        }
    }
    

    And on services.xml:

    <service id="max4.sms.listener"  class="Acme\DemoBundle\Listener\Logger">
            <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" />
            <argument type="service" id="router" />
            <argument type="service" id="service_container" />
    </service>
    

    You define the event you are listening to with

    <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" />
    

    And the arguments injected into the __construct() method (see http://symfony.com/doc/current/components/dependency_injection/introduction.html) with:

    <argument type="service" id="router" />
    <argument type="service" id="service_container" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I'm working with a company that has several different projects, all running on
Currently I am working in YII framework, Where I created a class that extends
Currently, I'm working on a project where I have a server - client relationship
Currently I have 2 ways of displaying images in a cell, which way will
Currently working with converting SQLException error messages into messages that are more useful for
Currently, I'm working on to get a list of all running applications. I've been
currently i am working on asp.net mvc where by mistake i have right clicked
Currently after my form has passed validation it forwards to an html page. I
Currently I am loooking for a way to develop an algorithm which is supposed
Currently I am working on small application in asp.net mvc. It is a some

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.