symfony-2.3

How to specify default format for FOS\\RestBundle to json?

微笑、不失礼 提交于 2019-12-01 03:26:15
My corresponding configuration is fos_rest: view: view_response_listener: force sensio_framework_extra: view: annotations: false and it really annoys to specify the route as @Route("/jobs", defaults={ "_format" = "json" }) every time. So is it possible to specify it somewhere to be assumed by default? PS: If I remove defaults={ "_format" = "json" } and call the /jobs endpoint I'm getting an exception Unable to find template "APIBundle:Jobs:post.html.twig". PPS: routing_loader: default_format: json won't work because it's only used for automatic routes generation. The final answer is much

Specify different validation groups for each item of a collection in Symfony 2?

孤人 提交于 2019-11-30 03:30:00
[ Documentation about collection ] When embedding forms (collection type) is possible to specify validation groups for each item, based on the current item? It seems not working ATM. The TaskType form adding a collection of tags: // src/Acme/TaskBundle/Form/Type/TaskType.php // ... public function buildForm(FormBuilderInterface $builder, array $options) { // ... $builder->add('tags', 'collection', array( // ... 'by_reference' => false, )); } For example we have two tags (tag 1 and tag 2) and a new tag is added using the "Add" button (via JavaScript): ----------- | add tag | ----------- - tag 1

Symfony Security: Auth with session or oauth

拜拜、爱过 提交于 2019-11-29 12:01:56
I have developed a REST API, there are two ways to connect to it: session and oauth. Basically, my website will use the session mode and third-party softwares will use the oauth mode. I managed to make make both session and oauth modes to work in symfony, but I can't make them work at the same time. Here is my firewalls security config: firewalls: auth_oauth_token: pattern: ^/auth/oauth/v2/token security: false api: pattern: ^/api anonymous: false fos_oauth: true stateless: true auth: pattern: ^/ anonymous: ~ form_login: login_path: /auth/session/check check_path: /auth/session/login always

Specify different validation groups for each item of a collection in Symfony 2?

妖精的绣舞 提交于 2019-11-29 01:06:53
问题 [Documentation about collection] When embedding forms (collection type) is possible to specify validation groups for each item, based on the current item? It seems not working ATM. The TaskType form adding a collection of tags: // src/Acme/TaskBundle/Form/Type/TaskType.php // ... public function buildForm(FormBuilderInterface $builder, array $options) { // ... $builder->add('tags', 'collection', array( // ... 'by_reference' => false, )); } For example we have two tags (tag 1 and tag 2) and a

No cache header with annotation

半腔热情 提交于 2019-11-29 00:12:11
In order to set the response without the cache in the controller you can do this: $response = new Response(); $result = $this->renderView( 'AcmeDemoBundle:Default:index.html.twig', array('products' => $products, 'form' => $form->createView())); $response->headers->addCacheControlDirective('no-cache', true); $response->headers->addCacheControlDirective('max-age', 0); $response->headers->addCacheControlDirective('must-revalidate', true); $response->headers->addCacheControlDirective('no-store', true); $response->setContent($result); return $response; But using annotations, to ensure that each

Symfony2 LTS: how to upgrade from 2.3 to 2.7?

一曲冷凌霜 提交于 2019-11-28 20:58:18
Symfony 2.7 was released on 30th April 2015 and is the current LTS (Long Term Support) version after the 2.3 version . Maintenance for these versions will end on May 2016 for Symfony 2.3 and May 2018 for Symfony 2.7. Security fixes will be released during one year after end of maintenance for both versions. As suggested by Massimiliano Arione in the announce comments , what are the changes required to upgrade from Symfony 2.3 from 2.7 without having to check all the minor upgrades (2.3 → 2.4, 2.4 → 2.5, etc.)? As reminded by Med in a comment, Symfony2 developers have tried to keep backward

Translations in Symfony 2.3 locale in request

夙愿已清 提交于 2019-11-28 13:58:37
How can I change locale in Symfony 2.3 ? I created this controller: public function changelocaleAction($lang) { $request = $this->get('request'); $request->setLocale($lang); return $this->redirect($request->headers->get('referer')); } It doesn't show changes when the page is refreshed. Why? Based on Symfony2 documentation : namespace Acme\LocaleBundle\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class LocaleListener implements EventSubscriberInterface {

How do I read from parameters.yml in a controller in symfony2?

故事扮演 提交于 2019-11-28 03:21:36
I have put a couple of custom variables in my app/config/parameters.yml. parameters: api_pass: apipass api_user: apiuser I need to access these from my controller, and have tried to fetch them with $this->get('api_user'); from within my controller file. When I try this, I get this error message: You have requested a non-existent service "api_user". What is the correct way to do this? Vitalii Zurian In Symfony 2.6 and older versions , to get a parameter in a controller - you should get the container first, and then - the needed parameter. $this->container->getParameter('api_user'); This

Symfony how to return all logged in Active Users

徘徊边缘 提交于 2019-11-27 18:53:07
I want to return all Logged in users of my application and render it in my Dashboard. The user_id and user_name should be retrieved from the session (I am using an external LDAP Library for authentication) I have created a field in the database called lastActivity which will contain the last login time and then I can query the database for lastActivity display users logged in in the last 2 minutes. ActivityListener.php <?php namespace Bnpp\SecurityBundle\EventListener; use Doctrine\ORM\EntityManager; //use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core

Call PHP function from Twig template

岁酱吖の 提交于 2019-11-27 15:27:10
I have a function in my controller that returns array of entities so in my twig template I do this to iterate over elements: {% for groupName, entity in items %} <ul> <ul> {% for element in entity %} <li>{{ element.getLabel }}</li> <li><input type="text" name="detail[{{ element.getId }}]" id="pd_{{ element.getId }}" /><input type="text" name="price[{{ element.getId }}]" id="pd_price_{{ element.getId }}" /><input type="text" name="stock[{{ element.getId }}]" id="pd_stock_{{ element.getId }}" /></li> {% endfor %} </ul> </ul> {% endfor %} In my controller I have also this PHP function: private