/** * create client. only admin is granted. * @Route("/admin/createclient", name="createclient") * @Security("has_role('ROLE_ADMIN')") */ public function createClient(Request $request) { $em = $this->getDoctrine()->getManager(); $client = new Client(); //设置会员级别 $normal = $em->getRepository('AppBundle:RoleName')->find(5); $client->setRoleName($normal); $role_name = $em->getRepository('AppBundle:RoleName')->find(4); $form = $this->createForm(new CreateClientType($role_name), $client); $direct_cities = array('北京市', '上海市', '天津市', '重庆市', '香港特别行政区', '澳门特别行政区', '台湾'); $hkmt = array('香港特别行政区', '澳门特别行政区', '台湾'); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $user = $client->getSingleUser(); $user->setRoleName($normal); $email = $_POST['createClient']['single_user']['email']; $client->setEmail($email); //设置对应的代理 if (isset($_POST['createClient']['agent'])) { $agent = $em->getRepository('AppBundle:User')->find($_POST['createClient']['agent']); $client->setAgent($agent); } //将地址写入数组 $this->setAddress($em, $direct_cities, $client, $hkmt); if (isset($_POST['createClient']['if_stock_purchased'])) { $client->setIfStockPurchased($_POST['createClient']['if_stock_purchased']); } if (isset($_POST['createClient']['if_insurance_purchased'])) { $client->setIfInsurancePurchased($_POST['createClient']['if_insurance_purchased']); } if (isset($_POST['createClient']['if_fund_purchased'])) { $client->setIfFundPurchased($_POST['createClient']['if_fund_purchased']); } if (isset($_POST['createClient']['if_future_purchased'])) { $client->setIfFuturePurchased($_POST['createClient']['if_future_purchased']); } $user->setSingleClient($client); $em->persist($client); $em->flush(); $redirect_url = $this->generateUrl('clientslist'); return new Response("<script>alert('添加成功');window.location.href='{$redirect_url}';</script>"); } return $this->render('@FOSUser/Clients/create_client.html.twig', array('client' => $client, 'form' => $form->createView())); }