symfony-2.3

Disabling some checkboxes of choice widget in buildForm()

纵饮孤独 提交于 2019-12-22 18:54:17
问题 I have a form widget of type "choice" which is being displayed as a list of many checkboxes. Everything works great. So to stress it out: there is ONE widget, with MANY checkboxes (and NOT several checkbox widgets). Now, I want to disable some of those checkboxes. The data for that is avaliable in the $options-Array. Here is the buildForm()-function of my FooType.php ... public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('foo', 'choice', array('choices'

Symfony2 How to get the selected value from a select field with twig

孤街醉人 提交于 2019-12-22 09:24:53
问题 I have a form that has some bootstrap nav-tabs and I need to repeat in every nav-tabs some info that I have preloaded from a select type field. I can access to the Id with {{ dump(form.proveedor.vars.value) }} But I need the selected label value. How can I do this? 回答1: Hopefully I get you question correctly. {% set label = '' %} {% for choice in form.proveedor.vars.choices %} {% if choice.value == form.proveedor.vars.value %} {% set label = choice.label %} {% endif %} {% endfor %} {{ label }

How do I get Symfony forms to work with a REST API?

我怕爱的太早我们不能终老 提交于 2019-12-22 05:19:27
问题 I'm currently trying to get symfony forms to work with my post and put rest api endpoint. Currently I have: $request = $this->getRequest(); $cc = new CreditCard(); $form = $this->createForm(new CreditCardType(), $cc); $form->handleRequest($request); if ($form->isValid()) { //... } However, the form is never valid. Looking into the problem, it seems that the form's isSubmitted field is false, so it never passes validation. Also, since this is an api call, I have the csrf_protection set to

How to change form field value in symfony 2

懵懂的女人 提交于 2019-12-21 03:33:13
问题 I have a form like below: class ItemType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder // ... ->add('tags','text',array( 'required' => false, 'attr' => array('name' => 'tags'), 'mapped' => false)) ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'MyBundle\ItemBundle\Entity\Item', 'cascade_validation' => true, )); } } My edit action public function editAction

How to change form field value in symfony 2

点点圈 提交于 2019-12-21 03:33:04
问题 I have a form like below: class ItemType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder // ... ->add('tags','text',array( 'required' => false, 'attr' => array('name' => 'tags'), 'mapped' => false)) ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'MyBundle\ItemBundle\Entity\Item', 'cascade_validation' => true, )); } } My edit action public function editAction

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

本小妞迷上赌 提交于 2019-12-19 05:42:52
问题 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:

show/hide some menus depend on the Sonata admin ROLE

依然范特西╮ 提交于 2019-12-19 04:04:09
问题 I'm working on a web project using Symfony2 , and i used Sonata Admin for the admin Panel , every thing works fine but what i want to do is ,on the dashboard menus of sonata Admin , i need to show hide some menus depend on the admin ROLE , so did any one do this before or know how to do it ? i tryed to use the config of the roles but when i'm connecting with a ROlE diffrent of ROLE_SONATA_ADMIN the top menu dont show up , - { path: ^/admin, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN,ROLE_ADMIN_NEWS

Symfony Security: Auth with session or oauth

你说的曾经没有我的故事 提交于 2019-12-18 06:58:03
问题 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

How to give container as argument to services

﹥>﹥吖頭↗ 提交于 2019-12-17 09:38:11
问题 in my services constructor public function __construct( EntityManager $entityManager, SecurityContextInterface $securityContext) { $this->securityContext = $securityContext; $this->entityManager = $entityManager; I pass entityManager and securityContext as argument. also my services.xml is here <service id="acme.memberbundle.calendar_listener" class="Acme\MemberBundle\EventListener\CalendarEventListener"> <argument type="service" id="doctrine.orm.entity_manager" /> <argument type="service" id

How does the login check_path route work without default controller/action?

半世苍凉 提交于 2019-12-17 05:01:43
问题 I am working on symfony 2.3 project having the following routing code just2_frontend_logincheck: pattern: /login_check It doesn't have defaults:{ _controller: testBundle:User:login } But it is working. But I don't know how the routing is working. Is it possible? Please advice me about the routing. 回答1: The check_path route/path is used by your firewall to catch login requests. This route's action is never really accessed. It's the route/url your login form posts to and the request should be