Php Symfony2:使用下拉列表编辑表单问题

Php Symfony2:使用下拉列表编辑表单问题,php,symfony,Php,Symfony,我在编辑表单中自动填写下拉列表时遇到问题。具有另一个文本框(文章标题)和一个下拉列表(持续时间)的表单填写了正确的值,但没有填写“国家和州”下拉列表。虽然我传递的是价值观,但它并没有反映在形式上 以下是我的控制器功能: public function addtrailsAction(Request $request) { $em = $this->getDoctrine()->getManager(); // print_r($_POST); $id = $re

我在编辑表单中自动填写下拉列表时遇到问题。具有另一个文本框(文章标题)和一个下拉列表(持续时间)的表单填写了正确的值,但没有填写“国家和州”下拉列表。虽然我传递的是价值观,但它并没有反映在形式上

以下是我的控制器功能:

public function addtrailsAction(Request $request) {

    $em = $this->getDoctrine()->getManager();

  // print_r($_POST);
   $id = $request->get('trailid');

   $userForm = new BidUserRequest();
    $user = $this->getUser();
    $memberId = $user->getId();
    $table = 'BidUser';
    //Get user detail by logged in member.
    $userDetail = $em->getRepository('AdventureLoginBundle:BidMember')->getDetailByMemberId($memberId,$table);

    $userid =$this->getUser()->getId();

    $clicknblog = $this->get('adventure_bridge.clicknblog');
    $counttrail= $clicknblog->checkusertrails($userid,$id);

    foreach ($counttrail as $value) {
    }
    if($value > 0 ){
         $this->get('session')->getFlashBag()->add(
                    'warning', 'Trail already added.');
              return new RedirectResponse($this->generateUrl('adventure_bidding_user_view_trails'));
    }
    else{
     $clicknblog = $this->get('adventure_bridge.clicknblog');
     //$state= $clicknblog->getState('');
     //$country= $userForm->getCountry();
     $continent= $clicknblog->getCountries('');
     $activity= $clicknblog->getArticle($id);
     foreach ($activity as $value) {
         $name = $value['articleTitle'];
         $durationMax = $value['durationMax'];
         $zone = $value['zone'];
         $state = $value['state'];
         $country = $value['country'];
        //$activity = $value['typeOfActivity'];
     }
        var_dump($activity); // Printing all the values but state and country is not reflecting in the form
    //   $userForm->setActivity($activity);
     $userForm->setCountry($country);$userForm->setState($state);
     $userForm->setDay($durationMax);
     $userForm->setZone($zone);
     $userForm->setName($name);
     $userForm->setTeam(0);
     $requestForm = $this->createForm(new RequestUserType(), $userForm);
        var_dump($userForm); //Printing all the values but state and country is not reflecting in the form
        die();
    // $requestForm->remove('country');

        return $this->render('AdventureBiddingBundle:User:trailRequestUser.html.twig', array(
        'activity' => $activity,
        'state' => $state,
        //'country' => $country,
        'continent' => $continent,
        'Form' => $requestForm->createView()

    ));


    }
} 
哪里有问题,请帮忙。我是个新手

更新:我的第一次
var\u转储
结果:

array(1) {
  [0]=>
  array(8) {
["id"]=>
string(1) "5"
["durationMax"]=>
string(1) "2"
["articleTitle"]=>
string(40) "Paramotoring with camp Tikkling, Gurgaon"
["difficulty"]=>
string(5) "basic"
["zone"]=>
string(5) "north"
["continent"]=>
string(1) "1"
["country"]=>
string(3) "356"
["state"]=>
string(7) "Haryana"
 }
}

当你在评论中说:“州和国家没有反映在表格中,你是说它们是空的吗?”?您能显示
$activity
的确切var\u转储吗?它们在var\u转储中不是空的,我从
$activity
var\u转储中更新了我的问题,您有任何错误吗?如果使用Symfony工具栏,您应该能够看到SQL请求和操作rejectedIt显示执行了5个查询和1个无效实体…这是什么意思?关联Adventure\BiddingBundle\entity\continents#countries指的是拥有方字段Adventure\BiddingBundle\entity\countries#Continentary,它没有定义为关联,而是定义为字段。关联Adventure\BiddingBundle\Entity\Continumes#countries是指不存在的拥有方字段Adventure\BiddingBundle\Entity\countries#Continument。