Fabien
Fabien

Reputation: 548

Symfony Controller executed multiple Time

When a user access to my page, i dispatch an visitedEvent in my showAction of my controller. This event must increment a view counter in my database.

My problem is that my controller seem to be called multiple times (two times) to show my page. My counter is always incremented twice !

I'm certain that my event is only dispatched here (its not dispatch in an other controller)

WHAT IS THE PROBLEM ??? how can i create a counter who is incremented only once time ?!

Think's

Upvotes: 1

Views: 1018

Answers (2)

Fabien
Fabien

Reputation: 548

After many search, I've found in my view an image with src="#"witch cause this issue.

Think's all for your help !

Upvotes: 1

Cristian Bujoreanu
Cristian Bujoreanu

Reputation: 1167

Probably you should create an service that handles this, saving your visitor data and call it simple in your controller:

$this->container->get('my.tracking.service')->storeThisVisit($params);

Upvotes: 0

Related Questions