php - "Request does not exist"创建表单 symfony2

标签 php forms symfony request

我是 php 和 symfony2 的菜鸟。

我正尝试按照教程 http://symfony.com/doc/current/book/forms.html 创建一个表单和其他一些教程。

我收到“500 内部错误”,我不知道我什么时候失败了,我正在伤脑筋。需要帮助,请

日志:

[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"} []    

路由.yml:

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

这是我在 SeriesController 中的 Action Controller :

    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(),
        ));
    }

类型,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';
    }
    }

和 nueva.html.twig

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

感谢您的帮助。

最佳答案

您的文件缺少这个简单的使用语句:

使用 Symfony\Component\HttpFoundation\Request;

但是:当您在同一个函数中使用 $request = $this->getRequest() 时,通过该函数传递 Request 是没有意义的。这是多余的。所以你真的可以这样做:

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

关于php - "Request does not exist"创建表单 symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33180477/

相关文章:

php - 如何阻止比较来自 2 个表的数据的链接

php - SQL 多重 OR 链查询

php - SQL WHERE 如果字段被序列化

javascript - 在 Firefox 中捕获提交有效,但在 Chrome 中无效

asp.net-mvc - MVC传统表单 Action 不调用 Controller 方法

php - Symfony 2.4 在 TWIG 中渲染 Controller 抛出 "Rendering a fragment can only be done when handling a Request."异常

php - 无法让登录路由在 Symfony 2 中工作

PHP 速记在新服务器上不起作用?

javascript - 如何在 Prod 中启动 Webpack 和装置

php将多个值插入到mysql表中的单独行中