I'm noob in php and symfony2.
I'm trying to create a form following the tutorial http://symfony.com/doc/current/book/forms.html and some other tutos.
I received "500 internal error", i don't know when i fail and i'm breaking my brain. Need help, plz
log:
[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(),
));
}
The 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 the nueva.html.twig
{% block body %}
<form action="{{ path('nueva_serie') }}" method="post">
{{ form_widget(form) }}
<input type="submit" />
</form>
{% endblock %}
Thanks for your help.
You file is missing this simple use statement:
use Symfony\Component\HttpFoundation\Request;
However: there's no point in passing Request through the function when you are using $request = $this->getRequest()
within that same function. It's redundant. So really you could just do this:
public function nuevaAction()
{
$request = $this->getRequest();
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With