I am trying to call entityManager
in formType
. I don't get why this is not working.
FormType :
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
Controller:
$form = $this->createForm(ProductsType::class, $products);
Services:
apx.form.type.product:
class: ApxDev\UsersBundle\Form\ProductType
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: form.type }
Error:
Catchable Fatal Error: Argument 1 passed to MyBundle\Form\FormType::__construct() must implement interface Doctrine\Common\Persistence\ObjectManager, none given, called in vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php on line 90 and defined
Assuming your services.yml file is being loaded and that you copied pasted in the contents then you have a simple typo:
# services.yml
class: ApxDev\UsersBundle\Form\ProductType
should be
class: ApxDev\UsersBundle\Form\ProductsType
Let's look at your error
Argument 1 passed to MyBundle\Form\FormType::__construct()
So when you're instantiating FormType
we're talking about the argument you pass like so
$form = new \MyBundle\Form\FormType($somearg);
Your definition says
public function __construct(ObjectManager $manager)
Based on the second part of the error
must implement interface Doctrine\Common\Persistence\ObjectManager
it's obvious that ObjectManager
is an interface. So what that means is you have to implement that interface in the object you're injecting into your class because that's what you told PHP to expect. What that looks like is this
class Something implements \Doctrine\Common\Persistence\ObjectManager {
// Make sure you define whatever the interface requires within this class
}
$somearg = new Something();
$form = new \MyBundle\Form\FormType($somearg);
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