Are you implementing the new version of Symfony in your old symfony 2 project ? That's quite obvious in almost all the cases. We want to enjoy the latest features of symfony when we can, however is not always as simple as change your composer.json, run composer update and wait that everything works as a clock !
Upgrading will take more than that and you'll need to read carefully the new documentation of symfony 3 (read more about forms here). For now, let's solve this little issue :
Your controller
When you face this issue, your controller will probably look like this :
The error is pretty simple, you can't initialize directly createForm method with the first parameter as a new MyClass instance, instead we will call the static class property of the problem class like this :
Your formType
Your old formType may should look like :
As seen on the controller, the declaration type has changed in Symfony 3, to solve the problem we will change the second parameter of the ->add
property in the builder for:
And that would be enough to solve that frustrating and little error, with Symfony 3 type names were removed. Instead of referencing types by name, you must reference them by their fully-qualified class name (FQCN) instead.
Have fun !
0 Comments