我是php和symfony2中的noob。
我正在尝试按照教程http://symfony.com/doc/current/book/forms.html和其他一些tutos创建表单。
我收到了" 500内部错误",我不知道什么时候我失败了,而且我的脑子坏了。需要帮助,PLZ
日志:
[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}
这是我在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(),
));
}
类型,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 %}
感谢您的帮助。
答案 0 :(得分:8)
您的文件缺少这个简单的使用声明:
use Symfony\Component\HttpFoundation\Request;
但是:当您在同一个函数中使用$request = $this->getRequest()
时,通过函数传递Request是没有意义的。这是多余的。所以你真的可以这样做:
public function nuevaAction()
{
$request = $this->getRequest();
...