Skip to content

Instantly share code, notes, and snippets.

@mikemadisonweb
Last active November 3, 2015 09:10
Show Gist options
  • Save mikemadisonweb/418143f1f8121d037c62 to your computer and use it in GitHub Desktop.
Save mikemadisonweb/418143f1f8121d037c62 to your computer and use it in GitHub Desktop.
SF2
// get a ConstraintViolationList
$errors = $this->get('validator')->validate( $user );
// $_GET parameters
$request->query->get('name');
// $_POST parameters
$request->request->get('name');
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* RedirectResponseWithCookie represents an HTTP response doing a redirect and sending cookies.
*/
class RedirectResponseWithCookie extends RedirectResponse
{
/**
* Creates a redirect response so that it conforms to the rules defined for a redirect status code.
*
* @param string $url The URL to redirect to
* @param integer $status The status code (302 by default)
* @param Symfony\Component\HttpFoundation\Cookie[] $cookies An array of Cookie objects
*/
public function __construct($url, $status = 302, $cookies = array ())
{
parent::__construct($url, $status);
foreach ($cookies as $cookie)
{
if (!$cookie instanceof Cookie)
{
throw new \InvalidArgumentException(sprintf('Third parameter is not a valid Cookie object.'));
}
$this->headers->setCookie($cookie);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment