symfony

How to dynamically add's collections within collections in Symfony2 form types

浪子不回头ぞ 提交于 2021-02-07 01:54:36
问题 I have 3 form types in symfony2 FaultType which is the parent of all next collections <?php namespace My\FaultBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class FaultType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('title') ->add('steps', 'collection', array( 'type' => new StepType(), 'allow_add' => true, 'prototype' => true, 'by_reference' => false, )) ->add('created') ->add('updated'

How to dynamically add's collections within collections in Symfony2 form types

血红的双手。 提交于 2021-02-07 01:53:44
问题 I have 3 form types in symfony2 FaultType which is the parent of all next collections <?php namespace My\FaultBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class FaultType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('title') ->add('steps', 'collection', array( 'type' => new StepType(), 'allow_add' => true, 'prototype' => true, 'by_reference' => false, )) ->add('created') ->add('updated'

Symfony 'trans' domain inside Twig template

强颜欢笑 提交于 2021-02-06 09:41:05
问题 I'd like to do this: $this->get('translator')->trans('notice.unregistered', array(), 'index'); Inside Twig template, so I don't have to pass this as an argument. How? 回答1: You can also do using trans filter : {{ 'translationkey'|trans({},'domain') }} 回答2: The solution is: {% trans from "domain" %}text{% endtrans %} 回答3: You can add custom functions to change domains inside your templates. Add your functions: $getTextdomain = new Twig_SimpleFunction('get_textdomain', function () { return

Newest symfony installer vs composer

只愿长相守 提交于 2021-02-06 08:50:51
问题 I'd like to know whats the difference when creating new symfony project with new symfony installer that has appeared last time and old-way composer. I've installed latest version of symfony (2.6.1) with both, and result was different, for example when I install symfony with composer, i get .gitignore file. When I install with new symfony installer script, gitignore is missing. Here is amount of catalogs and files in fresh project: symfony installer: 1498 directories, 7136 files symfony

Calls to isSumbitted() and isValid() result in “undefined method” error

这一生的挚爱 提交于 2021-02-05 12:26:08
问题 I have a Symfony form that is created from createFormBuilder() in the controller. But under two IF statements the form should carry two different set of fields. My Symfony version is 3.4. /src/AppBundle/Controller/DefaultController.php Ex: This is the basic form. $form = $this->createFormBuilder() ->add('name', TextType::class, ['required' => true]]) ->add('email', EmailType::class, ['required' => true]]) ->getForm(); if ($form->isSubmitted() && $form->isValid()) { ... ... ... } Now I need to

How to inject services dynamically into Symfony Command based on command argument.

好久不见. 提交于 2021-02-05 11:26:36
问题 I have a Symfony command that takes an argument which serves as a locator to a specific service required (based on that argument). ie. bin/console some:command service-locator-id with Symfony 2.8 you can simply fetch the service from the container $service = $this->container->get($input->getArgument('service-locator-id')); With Symfony 3.4 however, the container is deprecated and we should be using Dependency Injection. How do I inject the service that I require based on the argument being

Dynamic Generation for Submitted Forms with Form events

落爺英雄遲暮 提交于 2021-02-05 10:47:07
问题 I've a little problem with FormEvents, I want do 3 fields populated dynamically. I explain, I've 3 fields: Project > Box > Cell, the user choose a Project, the Box list is updated, he choose a Box, the cell list is updated. To do it, I use FormEvent like the documentation say (http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html#cookbook-form-events-submitted-data) But I've a problem, for just one field dynamically updated, it's work, but no for 2 fields... Actually a

Symfony 5 (Including 4) using Gedmo Doctrine Extension for SoftDelete

前提是你 提交于 2021-02-05 09:26:29
问题 I have tried to use soft delete (Using gedmo/doctrine-extensions) for some Entities in Symfony 5, and got some troubles: Listener "SoftDeleteableListener" was not added to the EventManager! Compile Error: App\Entity\Admin and Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity define the same property ($deletedAt) in the composition of App\Entity\Admin. However, the definition differs and is considered incompatible. Class was composed This is what I tried, and it runs well Install gedmo/doctrine

Symfony translation with placeholder doesn't work

倖福魔咒の 提交于 2021-02-05 09:13:26
问题 I'm trying to translate my app with Symfony translate (5.1.*). I use Symfony 5.1. Basic translation work fine but I have problem with variable in twig. When I do {% trans with {'%name%': 'World'} from 'app' %}Hello %name%{% endtrans %} It works fine and the result is Hello World as expected. But if I do php bin/console translation:update --force en php bin/console cache:clear to generate the translation file, the result is Hello %name% . If in the translation file, I delete this reference:

Take “setFrom” name as in Gmail configuration using Swift Mailer

微笑、不失礼 提交于 2021-02-05 08:55:26
问题 I'm using Swiftmailer to send emails in Symfony project. $msg = (new \Swift_Message("Subject")) ->setFrom('xxx123@gmail.com') ->setTo('yyy@gmail.com') ->setBody($mailContent); In the received email, the name of Sender looks like xxx123 . But the name for this email id in its configuration is XXX YYY . I can use, ->setFrom('xxx123@gmail.com' => 'XXX YYY') but, I don't want to set name directly in the code as it may be changed to something else like YYY ZZZ . How can I achieve this? Thanks in