K
K
kapai692014-02-08 14:54:30
symfony
kapai69, 2014-02-08 14:54:30

How to check the existence of cookies in Symfony2?

How best to check for the existence of cookies:
1 Immediately in the controller

public function storesAction(Request $request)
{
  	$city = $request->cookies->get('city');     
        if(....)
}

2 Redirect the cookie to the controller and check it there, and then return it back
public function storesAction(Request $request)
{
  	$city = $this->forward('checkCookieAction'); 
        if(....)
}

Or another option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GHua, 2014-02-08
@GHua

It can be defined as a service, receive a request, entity_manager (if $city is an instance of the model), and perform the necessary "checks" on some event like kernel.request. In the right place to pull the service and get the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question