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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:18:22+00:00 2026-06-02T05:18:22+00:00

I listen to the kernel.controller action to implement a default (or init) action foo

  • 0

I listen to the kernel.controller action to implement a default (or init) action foo my controllers:

public function onKernelController(FilterControllerEvent $event)
{
    $controller = $event->getController();

    if (!is_array($controller)) {
        return;
    }

    $currentController = $controller[0];
    if($controller[0] instanceof Initmethod){
        $ret = $currentController->init($event->getRequest());
        if($ret !== null && $ret instanceof Response){
            $ret->send();
            exit();
        }
    }

    $event->setController($controller);
}

As you can see, i want to give my init action the ability to return a response which should be send instead of the one of the called action. After that no other action should be executed.

My question is, is the way i’m doing it the right one? Because a don’t want to “fight the framework” and ending the execution by calling exit doesn’t seems do be right.

  • 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-02T05:18:24+00:00Added an answer on June 2, 2026 at 5:18 am

    You can set init method of controller as current callable method e.g

    $initController = array($currentController, 'init');
    $event->setController($initController);
    

    Then Symfony will process init method insted of default controller method and return the response if exists. I am assuming that you want to call the default controller method if init method returns null. In that case you can get method paremeters of that method using reflection, map function args and then invoke the method.

    Edit:

    It seems that I have misunderstood your problem. You want to avoid other listener operations like kernel.view, kernel.response etc. I think your solution is OK. But if you set session variable in your init method it will not be saved as it done by ContextListener which is called during kernel.response event.

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

Sidebar

Related Questions

I would like to listen for the mouse over event in GWT 1.6. Since
Say if I listen for an event: Subject.NewEvent += delegate(object sender, NewEventArgs e) {
I am trying to listen tab-in tab-out action for my swing gui that is
How do I listen to click event on a ListView? This is what I
Is it possible to listen a incomming notification such as : event from calendar,
I want to listen on an event (clipboard event ?) in order to alter
i am trying to listen to ETW kernel events. Step 1: Call OpenTrace ,
how can I listen, in an activity, to an event triggered in another activity?
I listen for a onload event on a main window, then for a DOMContentLoaded
How to listen to drag event when a jquery-ui-sortable is being dragged? By hit-n-trial

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.