symfony3.x

Choice field default value

让人想犯罪 __ 提交于 2020-01-20 04:29:04
问题 I have the following form: public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('type', ChoiceType::class, array( 'expanded' => true, 'multiple' => false, 'choices' => array( 'Friend' => 'friend', 'Guide' => 'guide' ) )); } How can I make 'Friend' checkbox to be checked by default when the form is rendered ? 回答1: I think you should try with data option, but it's just in the case where you don't even have a data saved inside your object, because it will

FOSUserBundle - PHPUnit - Mock a user

孤街醉人 提交于 2019-12-18 08:55:37
问题 I am using Symfony with the FOSUserBundle and now I like to test some things like: Doctrine lifecycle Controller behind firewall For those tests I need to be a specific user or at least in a user group. How do I mock a user session so that ... The lifecycle field like "createdAt" will use the logged in user The Controller act like some mocked user is logged in Example: class FooTest extends ... { function setUp() { $user = $this->getMock('User', ['getId', 'getName']); $someWhereGlobal->user =

How to edit/update a many to many relationship in Symfony 3 from the inverse side

落花浮王杯 提交于 2019-12-12 04:38:43
问题 I'm working on a bash script that create a simple project "from zero to CRUD" with some tool and Symfony 3 bin/console doctrine:generate:* It works fine but in the M:N association case i can't update data from the inverse side. I read some answers here and i started some tests but i'm confused among "cascade={"all"}" option, 'by_reference' => false and other suggests. What is the simplest way to do that starting from this basic example taken from the offical doctrine docs? /** @Entity */

Symfony3 : multi-steps form and flush after forward

家住魔仙堡 提交于 2019-12-11 07:32:21
问题 I have a form to add a new prescriber in my database. The first step consists in informing the various informations about the prescriber. Then, I check if there are similar prescribers before adding it (2nd step with a 2nd form) and if there are, I ask the user to confirm. In short, I have a 1-step form or a 2-steps form, depending on duplicates. I tried with CraueFormFlowBundle but I don't know how to implement my conditional second step. My tests were inconclusive. So I decided to use

How to configure PhpStorm to use symfony/phpunit-bridge

旧时模样 提交于 2019-12-03 05:38:24
问题 I had problems with configuring PhpStorm IDE to use http://symfony.com/doc/current/components/phpunit_bridge.html while working with Symfony 3.3. I decided to just download phpunit.phar to bin and use it instead. Symfony 3.4 (and Symfony 4), does not even have phpunit.xml.dist out of the box, so there is a problem with using phpunit.phar easily. I've installed PHPUnit using flex: composer req phpunit That created phpunit.xml.dist and I was able to run tests from command line by: php bin

How to configure PhpStorm to use symfony/phpunit-bridge

南楼画角 提交于 2019-12-02 19:00:11
I had problems with configuring PhpStorm IDE to use http://symfony.com/doc/current/components/phpunit_bridge.html while working with Symfony 3.3. I decided to just download phpunit.phar to bin and use it instead. Symfony 3.4 (and Symfony 4), does not even have phpunit.xml.dist out of the box, so there is a problem with using phpunit.phar easily. I've installed PHPUnit using flex: composer req phpunit That created phpunit.xml.dist and I was able to run tests from command line by: php bin/phpunit But again I could not make PhpStorm use it. So I downloaded phpunit.phar and it can work together

Choice field default value

◇◆丶佛笑我妖孽 提交于 2019-11-29 05:33:31
I have the following form: public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('type', ChoiceType::class, array( 'expanded' => true, 'multiple' => false, 'choices' => array( 'Friend' => 'friend', 'Guide' => 'guide' ) )); } How can I make 'Friend' checkbox to be checked by default when the form is rendered ? I think you should try with data option, but it's just in the case where you don't even have a data saved inside your object, because it will override it else. Important : It's good for create action, but not for edit action. public function buildForm