I have StudentCourse entity with this column
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User\RegisteredUser", inversedBy="studentCourses")
* @ORM\JoinColumn(nullable=false)
*/
private $student;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Course\Course", inversedBy="studentCourses")
* @ORM\JoinColumn(nullable=false)
*/
private $course;
Then I have form type
namespace App\Form\StudentCourse;
use App\DataHolder\StudentCourse\StudentCourseNewDetails;
use App\Entity\Course\Course;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class NewStudentCourseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('course', EntityType::class, [
'class' => Course::class,
'choice_label' => 'title'
])
->add('student', HiddenType::class, [
'data'=>$options['student']
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => StudentCourseNewDetails::class
]);
}
}
and in controller
$form = $this->createForm(NewStudentCourseType::class, $scnd, [
'student' => $user
]);
when i try display form this error i obtain
The option "student" does not exist. Defined options are: "action", "allow_extra_fields", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "help", "help_attr", "help_html", "help_translation_parameters", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "label_translation_parameters", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".