dougaopu7938
2017-11-25 12:35
浏览 37
已采纳

从控制器获取值以形成symfony 3

I don't know why i can't get the value on form from the variable of controller.

My controller:

public function indexAction(Request $request,$id){
    $ac = new Usersacademi();
    $form = $this->createForm(UsersacademiType::class,$ac,array('id'=>$id));
    $form->handleRequest($request);

    if($form->isValid()){
        $ac->setIdacademicprogram($form->get("idacademicprogram")->getData());
        $ac->setIduser($form->get("iduser")->getData());
        $em = $this->getDoctrine()->getManager();
        $em->persist($ac);
        $flush = $em->flush();
    }
    else{
    }


    return $this->render("AppBundle:admin:apteacher.html.twig", array(
        "form" => $form->createView()
    ));
}

My form:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('idacademicprogram', EntityType::class, array(
            "required"=>"required",
            'class' => 'AppBundle:Academicprogram',
            'choice_label' => 'name'
        ))
        ->add('iduser', NumberType::class, array("required"=>"required",
            "data" =>$options["id"],
            "attr"=>array(
            "class" => "form-iduser form-control"
        )));
}

And i'm getting this error:

The option "id" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "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", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题