Hi, i really need some help for a complex form.
Here is some code:
Entity 1
<?php
/**
* @ORM\Table(name="_frais")
* @ORM\Entity
*/
class Frais
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="Taux", cascade={"persist"},
fetch="EAGER")
* @ORM\JoinTable(name="_frais_taux",
* joinColumns={@ORM\JoinColumn(name="frais_id",
referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="taux_id",
referencedColumnName="id")}
* )
*/
private $taux;
/**
* @ORM\Column(name="label", type="string", length=100, nullable=true)
*/
private $label;
}
Entity 2
<?php
/**
* @ORM\Table(name="_taux")
* @ORM\Entity
*/
class Taux
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(name="label", type="string", length=100, nullable=true)
*/
private $label;
}
Form
<?php
class FraisType extends AbstractType
{
/**
* @param \Symfony\Component\Form\FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('label', 'text', array(
'label' => 'label',
'max_length' => 100,
'required' => true
))
->add('taux', 'entity', array(
'label' => 'Taux',
'class' => 'Bundle:Taux',
'property' => 'label',
'required' => false,
'empty_value' => 'Sélectionner',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('t')
->orderBy('t.label', 'ASC');
},
'multiple' => true,
'expanded' => true
));
}
/**
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface
$resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Bundle\Entity\Frais',
'cascade_validation' => true,
));
}
/**
* @return string
*/
public function getName()
{
return 'bundle_frais';
}
}
At this point all is working fine.
Now i have to make a dynamic form where the user have to fill input value
for each couple of "Frais - Taux", that mean, foreach taux in frais add a
custom field to fill...and i don't know how i can do this, here is my third
class
Entity 3
<?php
/**
* @ORM\Table(name="_saisie")
* @ORM\Entity
*/
class Saisie
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(name="label", type="string", length=100, nullable=true)
*/
private $label;
/**
* @ORM\ManyToOne(targetEntity="Frais", fetch="EAGER")
* @ORM\JoinColumn(name="frais_id", referencedColumnName="id",
nullable=false)
* @Assert\NotNull()
*/
private $frais;
/**
* @ORM\OneToMany(targetEntity="SaisieTauxFrais", mappedBy="frais",
cascade={"persist"})
*/
private $tauxFrais;
}
I don't know which properties to use in that class ($frais is a selectBox
where the data can be set from repository, and the javascript:onChange have
to update the $tauxFrais with a collection of "SaisieTauxFrais"), i'm
really lost
Here is what i have to do
Entity 4
<?php
class SaisieTauxFrais
{
/**
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Taux", inversedBy="taux",
cascade={"persist"})
* @ORM\JoinColumn(name="taux_id", referencedColumnName="id")
*/
private $taux;
/**
* @ORM\ManyToOne(targetEntity="Frais", inversedBy="frais",
cascade={"persist"})
* @ORM\JoinColumn(name="frais_id", referencedColumnName="id")
*/
private $frais;
/**
* @ORM\ManyToOne(targetEntity="Saisie", inversedBy="tauxFrais",
cascade={"persist"})
* @ORM\JoinColumn(name="saisie_id", referencedColumnName="id")
*/
private $saisie;
/**
* @ORM\Column(name="valeur", type="string", length=100, nullable=true)
* @Assert\NotBlank(message="champ requis")
*/
private $valeur;
}
The important thing in that class is the $valeur who have to be fill by the
user in my form, but i can have 0 or n input box depending on the
manytomany relationship frais -> taux
Any idea ?
A really simple thing on paper but really hard for implementing in sf2
--
--
If you want to report a vulnerability issue on Symfony, please read the
procedure on http://symfony.com/security
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
---
You received this message because you are subscribed to the Google Groups
"Symfony developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.