【发布时间】:2020-01-09 12:39:51
【问题描述】:
我在此列中有 StudentCourse 实体
/**
* @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;
然后我有表单类型
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
]);
}
}
在控制器中
$form = $this->createForm(NewStudentCourseType::class, $scnd, [
'student' => $user
]);
当我尝试显示这个错误时,我得到了
“学生”选项不存在。定义的选项有:“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"。
【问题讨论】: