In my database I have 2 tables:
Course table:
Session table:
The buildForm function in my SessionType looks like this:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('date');
}
The buildForm function in my CourseType looks like this:
$builder
->add('name')
->add('description')
->add('foreknowledge')
->add('teacher')
->add('sessions', CollectionType::class, array(
'entry_type' => SessionType::class,
'entry_options' => array('label' => false),
'allow_add' => true,
'by_reference' => false,
'allow_delete' => true,
))
My form in my twig template looks like this:
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}
But nothing is shown under "Sessions". I would like to have the possibility to create multiple sessions under my course. Is there an easy way to do this?
UPDATE:
When I try to save my course and do a dump just before I save I get this:
My sessions are saved, but they are not linked to course. How does this come?
That is possible and you are missing some javascript, it is very well documented here .
Instead of copy-pasting from that documentation page here, you can read it and ask if you need any help with it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.