"Request does not exist" by creating a symfony2 form

I am noob in php and symfony2.

I am trying to create a form after the tutorial http://symfony.com/doc/current/book/forms.html and some other tutos.

I got a β€œ500 internal error,” I don’t know when I will fail and I break my brain. Need help, plz

Magazine:

[2015-10-16 23:35:27] request.INFO: Matched route "nueva_serie". {"route_parameters":{"_controller":"Acme\\AxialBundle\\Controller\\SeriesController::nuevaAction","_route":"nueva_serie"},"request_uri":"http://pruebas.com/nueva-serie/"} []
[2015-10-16 23:35:27] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2015-10-16 23:35:27] request.CRITICAL: Uncaught PHP Exception ReflectionException: "Class Acme\AxialBundle\Controller\Request does not exist" at /home/jjrojo/estigia/vendor/sensio/framework-extra-bundle/EventListener/ParamConverterListener.php line 83 {"exception":"[object] (ReflectionException(code: 0): Class Acme\\AxialBundle\\Controller\\Request does not exist at /home/jjrojo/estigia/vendor/sensio/framework-extra-bundle/EventListener/ParamConverterListener.php:83)"} []
[2015-10-16 23:35:27] request.INFO: Matched route "_wdt". {"route_parameters":{"_controller":"web_profiler.controller.profiler:toolbarAction","token":"884636","_route":"_wdt"},"request_uri":"http://pruebas.com/_wdt/884636"} []    

routing.yml:

    nueva_serie:
    path:     /nueva-serie/
    defaults: { _controller: AcmeAxialBundle:Series:nueva}

Here is my action controller in SeriesController:

    public function nuevaAction(Request $request)
    {
        $request = $this->getRequest();

        $serie = new Serie();
        $form = $this->createForm(new SerieType(), $serie);
        if($request->getMethod() == 'POST')
        {
            $form->bindRequest($request);
            if($form->isValid()){
                //get data and flush
                return $this->redirect($this->generateURL('lista'));
            }
        }

        return $this->render('AcmeAxialBundle:Series:nueva.html.twig', array(
        'form' => $form->createView(),
        ));
    }

Type, SerieType.php:

    <?php
    namespace Acme\AxialBundle\Form\Type;
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilder;
    class SerieType extends AbstractType
    {
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('titulo')
                ->add('imagen')
                ->add('descripcion');
    }
    public function getName()
    {
        return 'form_serie';
    }
    }

and nueva.html.twig

    {% block body %}
    <form action="{{ path('nueva_serie') }}" method="post">
        {{ form_widget(form) }}
    <input type="submit" />
    </form>
    {% endblock %}

Thank you for your help.

+4
source share
1 answer

This simple use statement is missing from the file:

use Symfony\Component\HttpFoundation\Request;

: , $request = $this->getRequest() . . :

public function nuevaAction()
{
    $request = $this->getRequest();
    ...
+8

Source: https://habr.com/ru/post/1612002/


All Articles