Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony crud edict : Could not load type "datetime"

Context:

I create a project with symfony 3. My database have one table with a field datetime

With this commands I create a simple CRUD application for one table

php bin/console doctrine:mapping:import --force adminBundle xml

php bin/console doctrine:mapping:convert annotation ./src

php bin/console doctrine:generate:entities adminBundle

php bin/console generate:doctrine:crud

Error:

So my crud is done but when I edit one row throw an error

Could not load type "datetime" 500 Internal Server Error - InvalidArgumentException

Stack Trace

  in vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php at line 87

I think that could not load type “datetme”, I try register my form in the section services of my services.yml, but I don't know How to do it? for the type datetime.

Any idea? thanks in advance.

like image 870
Cyberguille Avatar asked Jan 21 '16 17:01

Cyberguille


2 Answers

Seems like a bug in the CRUD generator. It uses a type alias instead of the fully qualified class name:

$builder->add('fieldName', 'textarea');

The fully qualified class name is required since Symfony 3.0:

$builder->add('fieldName', DateTimeType::class);

Please check the generated form type.

like image 135
Sergey Fedotov Avatar answered Oct 02 '22 16:10

Sergey Fedotov


Sergey, thanks for pointing that out. I'm not sure why, but specifying the fully qualified class name didn't resolve the issue on my end. Removing the datetime alias all together did.

Changed:

$builder
  ->add('name')
  ->add('time', 'datetime')
  ->add('location')
;

To:

$builder
  ->add('name')
  ->add('time')
  ->add('location')
;
like image 42
Emir Memic Avatar answered Oct 02 '22 14:10

Emir Memic