A
A
ak_wi2019-10-09 16:00:26
symfony
ak_wi, 2019-10-09 16:00:26

symfony. How to set the current value in a form?

The client entity has a managerId property. Because the Customer entity is serializable, it is not possible to use a relationship with a Manager object that has image and file properties.

/**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $managerId;

In the client editing form, there is the following field, which correctly saves the manager's id in acc. client field.
->add('managerId', EntityType::class, [
                'class' => Manager::class,
                'mapped' => false,
                'label' => 'Личный менеджер',
                'choice_label' => 'name',
                'choice_value' => function (Manager $entity = null) {
                    return $entity ? $entity->getId() : '';
                },
                'required' => false,
                'multiple' => false,
                'expanded' => false,
                'query_builder' => function (EntityRepository $repo) {
                    return $repo->createQueryBuilder('s')
                        ->andWhere('s.status = :val')
                        ->setParameter(':val', Manager::STATUS_VISIBLE)
                        ->orderBy('s.name', 'ASC');
                },
            ])

The question is how to display the already selected manager from the client in this field in the editing form?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question