S
S
Siricks122016-12-06 09:13:31
symfony
Siricks12, 2016-12-06 09:13:31

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

And on the 51st line:
$form = $this->createForm(AccessesType::class, $enquiry);

On the local host, the same controller works quietly, when taken out to an external server - this is such an error in the log.
Whole code:
/**
     * Вывод одного доступа
     * @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

1 answer(s)
I
ig0r88, 2016-12-06
@Siricks12

Constants containing the name of a class (AccessesType::class) have been available since PHP 5.5. Apparently on an external server the version is lower.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question