我在编辑表单中自动填充下拉列表时遇到问题。具有其他文本框(文章标题)和一个下拉(持续时间)填写正确值而不是国家和州下拉列表的表单正在工作。虽然我传递的是价值,但没有反映在表格中。
这是我的控制器功能:
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_dump
结果:
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"
}
}