Symfony - Class AppBundle\Controller\Request does not exist

Hello,

Still struggling with symfony. I’m trying to reproduce the example given at http://symfony.com/doc/current/forms.html (a very simple form without doctrine involved) and I’m getting the message “Class AppBundle\Controller\Request does not exist” (though it does in /vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Request.php).

There may be somewhere a path that is missing. Here’s the code of lmy controller :

<?php
// src/AppBundle/Controller/TaskClassController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;

use AppBundle\Entity\TaskClass;

class TasksFormController extends Controller
	{
	public function tasksFormAction(Request $request)
		{
		$task = new TaskClass();
		$form = $this->createFormBuilder($task)
					 ->add('task', TextType::class)
					 ->add('dueDate', DateType::class)
					 ->add('save', SubmitType::class, array('label' => 'Create Task'))
					 ->getForm();
		$form->handleRequest($request);
		if($form->isSubmitted() && $form->isValid())
			{
			$task = $form->getData();
			return $this->redirectToRoute('TaskCreated', array('task' => $task,));
			}
		return $this->render('tasksForm.html.twig', array('form' => $form->createView(),));
		}
	}
?>

Thanks in advance,

MC

Here is the stack trace for this error :

Stack Trace

    in vendor/sensio/framework-extra-bundle/EventListener/ParamConverterListener.php at line 83  -
            private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations)
            {
                foreach ($r->getParameters() as $param) {
                    if (!$param->getClass() || $param->getClass()->isInstance($request)) {
                        continue;
                    }

Any related answer to this error tells to add “use Symfony\Component\HttpFoundation\Request;” but it is in my code…

Ok, my bad, I had forgotten “use Symfony\Component\HttpFoundation\Request;” in the “TaskCreated” controller…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.