Ich bin Anfänger symfony Entwickler. Ich habe großes Problem mit Form ich mag Daten auf meine Tabellennamen Kampagnen speichern, die wie folgt aussehen:Symfony 2 Formular mit mehreren Tabelle wählen Sie Typ
contacts_groups:
id, user_id, name, description, created
für Empfänger-System
Campaigns:
id, user_id, recipients, message, sender, type, created
und die nächsten
Ich habe 2 Tabellen in der Basis
und
contacts:
id, user_id, group_id, email, city, created.
lassen jetzt ‚S gehen davon aus, dass meine folgenden Tabellen Datensätze:
contacts_groups:
id, user_id, name, description, created
1, 1, Test Group, Newest recipients, 2016-20-02 14:24:00
2, 1, Awesome Group, Pro players, 2016-10-02 11:22:41
contacts:
id, user_id, group_id, email, city, created
1, 1 , 1, [email protected], New York, 2016-12-12 12:12:12
2, 1 , 1, [email protected], New York, 2016-12-12 12:12:12
3, 1 , 2, [email protected], New York, 2016-12-12 12:12:12
Jetzt i eine Form mit zwei Tabellen tun wollen zeichnet Beispiel:
TextField => text for sender name row
ChoiceType => select with options with contacts_groups records
ChoiceType => select with options with contacts where group_id == choosed contacts_groups record above.
ich habe diesen Code:
class CampaignsType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options) {
$Campaigns = $options['data'];
$user = $Campaigns->tmpusr; // variable transferred from the controller (logged user id)
$builder
->add('sender', TextType::class, array(
'trim' => true,
'label' => 'Odbiorca',
'label_attr' => array('class' => 'col-sm-2 control-label'),
'attr' => array('class' => 'form-control', 'maxlength' => '11')
))
->add('recipients', EntityType::class, array(
'label' => 'Grupa odbiorców',
'label_attr' => array('class' => 'col-sm-2 control-label'),
'attr' => array('class' => 'form-control'),
'class' => 'MyAppPanelBundle:ContactsGroups',
'query_builder' => function (\Doctrine\ORM\EntityRepository $er) use ($user) {
return $er->createQueryBuilder('u')
->select('u')
->add('where', 'u.user_id = ' . $user)
->orderBy('u.id', 'DESC');
},
'choice_value' => 'id',
'choice_label' => 'name',
));
}
Weiß jemand, wie man das nächste Feld mit Kontakten aus der Datenbank hinzufügt, wobei group_id
dasselbe ist wie die ID der ausgewählten Gruppe?
Danke an alle.
Um dies zu erreichen, müssen Sie Ajax verwenden, um eine Anfrage mit ausgewählter 'group' zu senden und als Antwort eine Liste von' contacts' [doc chapter] (http://symfony.com/doc/current/form/dynamic_form_modification.html) –