Answer the question
In order to leave comments, you need to log in
What is the error when creating a form in Symfony?
PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /var/www/project/src/ControlBundle/Controller/DefaultController.php on line 51
$form = $this->createForm(AccessesType::class, $enquiry);
/**
* Вывод одного доступа
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showOneAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$access = $em->getRepository('ControlBundle:Accesses')->find($id);
if (!$access) {
throw $this->createNotFoundException('Невозможно найти доступ с таким номером');
}
$enquiry = new Accesses();//создаем объект для формы
$form = $this->createForm(AccessesType::class, $enquiry);//создаем форму
$form->get('client_id')->setData($access->getClientId());//задаем значения из БД
$form->get('site')->setData($access->getSite());//задаем значения из БД
$form->get('address')->setData($access->getAddress());//задаем значения из БД
$form->get('login')->setData($access->getLogin());//задаем значения из БД
$form->get('password')->setData($access->getPassword());//задаем значения из БД
$form->get('type')->setData($access->getType());//задаем значения из БД
$form->get('id')->setData($access->getId());//задаем значения из БД
if ($request->isMethod($request::METHOD_POST)) {
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$task = $form->getData();
$em->merge($task);
$em->flush();
return $this->render('ControlBundle:Accesses:showOne.html.twig', array(
'status' => 'Изменения сохранены',
'access' => $access,
'form' => $form->createView()
));
}
}
return $this->render('ControlBundle:Accesses:showOne.html.twig', array(
'access' => $access,
'form' => $form->createView()
));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question