user1383973
user1383973

Reputation: 11

Symfony2: Call a Controller /File on EVERY action

I'm doing a huge project with Symfony2. Frontend is javascript/html5 canvas. For site changes I use ajax requests.

Now I want to call a php file which should be executed with EVERY user action. Is there an elegant way to do so?

For better understanding: I'm doing some kind of game and the php checks, if something happend (recruitments done, buildings finished etc.).

Upvotes: 1

Views: 1460

Answers (2)

Vincent Pazeller
Vincent Pazeller

Reputation: 1508

If by user action you mean executing a controller action (i.e. server side), what I would do is listen to the kernel.controller event: http://symfony.com/doc/current/book/internals.html

so you can load your script and execute it juste before the target controller is invoked

use Symfony\Component\HttpKernel\Event\FilterControllerEvent;

public function onKernelController(FilterControllerEvent $event)
{
    $controller = $event->getController();
    //...
    // call your php file here

    // the controller can be changed to any PHP callable
    $event->setController($controller);
}

I don't think you even need to modify the controller so you can remove the first and last line...

Upvotes: 0

Mun Mun Das
Mun Mun Das

Reputation: 15002

Take a look into JMSAopBundle

Upvotes: 1

Related Questions