I have the entity "News" with fields:
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="text")
*/
protected $description;
I generate the form in my controller:
public function createNewsAction(Request $request)
{
$news = new News();
$news->setName('New!');
$news->setDescription('test');
$form = $this->createFormBuilder($news)
->add('name', TextType::class)
->add('description', TextType::class)
->add('save', SubmitType::class, array('label' => 'Create Task'))
->getForm();
return $this->render('frontend/createNews.html.twig', array(
'form' => $form->createView(),
));
}
And when I try to call this method ("createNewsAction") I got the error:
Could not load type "Doctrine\DBAL\Types\TextType"
500 Internal Server Error - InvalidArgumentException
Stack Trace
in vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php at line 87 -
if (class_exists($name) && in_array('Symfony\Component\Form\FormTypeInterface', class_implements($name))) {
$type = new $name();
} else {
throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name));
}
}
What I do wrong with this code?
Check your use
statement at the top of your controller...
You've probably used:
use Doctrine\DBAL\Types\TextType
It should be:
use Symfony\Component\Form\Extension\Core\Type\TextType;
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