symfony-2.1

Symfony get form data in controller

孤人 提交于 2019-12-01 17:15:26
I have this view: //login.html.twig <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MY APP</title> </head> <body> <form action="{{ path('conection') }}" method="post" name="formulario_login"> <label for="username">User:</label> <input type="text" id="username" name="_username" value="{{ last_username|default('') }}" /> <br /> <label for="password">Password:</label> <input type="password" id="password" name="_password" /> <br /> <input type="checkbox" id="remember_me" name="_remember_me"/> <label for="remember_me">Remember me</label>

Symfony2 and Doctrine: how to fetch two different object for the same id?

故事扮演 提交于 2019-12-01 16:23:39
问题 I have this scenario: Object A have some reference to other objects B,C,D Object B have some reference to other objects A,F,G Object C have some reference to other objects A,... And so on. In my code, I need to make a "copy" of an object (say A) for tmp reasons (no, I can't use a different structure, I need to have a copy of object). If I use clone , obviously, I make a clone of my object but object related to him, aren't cloned. I perfeclty know that I can override magic-method __clone() in

How to retrieve a streamed response (e.g. download a file) with Symfony test client

时光怂恿深爱的人放手 提交于 2019-12-01 15:06:06
I am writing functional tests with Symfony2. I have a controller that calls a getImage() function which streams an image file as follows: public function getImage($filePath) $response = new StreamedResponse(); $response->headers->set('Content-Type', 'image/png'); $response->setCallback(function () use ($filePath) { $bytes = @readfile(filePath); if ($bytes === false || $bytes <= 0) throw new NotFoundHttpException(); }); return $response; } In functional testing, I try to request the content with the Symfony test client as follows: $client = static::createClient(); $client->request('GET', $url);

How to retrieve a streamed response (e.g. download a file) with Symfony test client

隐身守侯 提交于 2019-12-01 13:58:49
问题 I am writing functional tests with Symfony2. I have a controller that calls a getImage() function which streams an image file as follows: public function getImage($filePath) $response = new StreamedResponse(); $response->headers->set('Content-Type', 'image/png'); $response->setCallback(function () use ($filePath) { $bytes = @readfile(filePath); if ($bytes === false || $bytes <= 0) throw new NotFoundHttpException(); }); return $response; } In functional testing, I try to request the content

Detect locale and alter url (redirect) to include locale

五迷三道 提交于 2019-12-01 08:42:45
What i want to do is, to detect the language of a users browser and redirect him to a page containing the locale in url. I thought, the easiest way would be, to register a kernel listener. So that is what i did: services: kernel__request_listener: class: Me\MainBundle\Listener\KernelRequestListener tags: - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } calls: - [ setContainer, [ @service_container ] ] KernelRequestListener.php ... /** * @Service */ class KernelRequestListener { /** * @Observe("kernel.request") */ public function onKernelRequest(

Detect locale and alter url (redirect) to include locale

∥☆過路亽.° 提交于 2019-12-01 06:37:51
问题 What i want to do is, to detect the language of a users browser and redirect him to a page containing the locale in url. I thought, the easiest way would be, to register a kernel listener. So that is what i did: services: kernel__request_listener: class: Me\MainBundle\Listener\KernelRequestListener tags: - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } calls: - [ setContainer, [ @service_container ] ] KernelRequestListener.php ... /** * @Service */ class

Symfony2.1 mapping error: class_parents()

时光怂恿深爱的人放手 提交于 2019-12-01 05:27:28
问题 I have a problem trying to get data from a table (via entity) using Doctrine2 in a Symfony2.1 project. Here is the controller where I get the error: /** * Country list */ public function countrylistAction() { $em = $this->getDoctrine()->getManager(); $countryList = $em->getRepository('ProjectBaseBundle:SYS_TCountry') ->findAll(); $serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder())); return new Response($serializer->serialize($countryList, 'json

Symfony2 Select one column in doctrine

帅比萌擦擦* 提交于 2019-12-01 05:14:24
I'm trying to refine the query trying to select fewer possible values ​​.. For example I have an entity "Anagrafic" that contains your name, address, city, etc., and a form where I want to change only one of these fields, such as address. I have created this query: //AnagraficRepository public function findAddress($Id) { $qb = $this->createQueryBuilder('r') ->select('r.address') ->where('r.id = :id') ->setParameter('id', $Id) ->getQuery(); return $qb->getResult(); } there is something wrong with this query because I do not return any value, but if I do the query normally: //Controller $entity

Symfony2 Select one column in doctrine

主宰稳场 提交于 2019-12-01 02:07:48
问题 I'm trying to refine the query trying to select fewer possible values ​​.. For example I have an entity "Anagrafic" that contains your name, address, city, etc., and a form where I want to change only one of these fields, such as address. I have created this query: //AnagraficRepository public function findAddress($Id) { $qb = $this->createQueryBuilder('r') ->select('r.address') ->where('r.id = :id') ->setParameter('id', $Id) ->getQuery(); return $qb->getResult(); } there is something wrong

Get all errors along with fields the error is connected to

蓝咒 提交于 2019-11-30 15:57:38
I'm using Symfony2 forms to validate POST and PUT requests to an API. The form handles binding the request data to the underlying entity and then validating the entity. Everything is working pretty well except for collecting errors. I'm using the FOSRestBundle and am throwing a Symfony\Component\HttpKernel\Exception\HttpException with a 400 status code and a message containing the form error messages if validation fails. The FOSRestBundle handles converting this into a JSON response. The controller method I have to perform all of this looks like the following (all fields bubble their errors up