Reputation: 554
I'm trying to use doctrine in asymfony2 form type.
In services.yml I have:
fyp_user.profile.form.type:
class: FYP\UserBundle\Form\Type\ProfileFormType
arguments:
- fos_user.model.user.class
- @doctrine.orm.entity_manager
tags:
- { name: form.type, alias: fyp_user_profile }
My class looks like:
use Doctrine\ORM\EntityManager;
class ProfileFormType extends AbstractType
{
private $em;
private $session;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
I'm to do something like:
$cust = $this->em->getRepository('MyBundle:Customers')->findOneByEmail($email);
I keep getting
Type error: Argument 1 passed to FYP\UserBundle\Form\Type\ProfileFormType::__construct() must be an instance of Doctrine\ORM\EntityManager, string given, called in /Applications/MAMP/htdocs/upgrade/app/cache/dev/appDevDebugProjectContainer.php on line 3594
Thanks.
Upvotes: 0
Views: 115
Reputation: 10890
You have a mismatch between service definition and class constructor. In service definition you have two arguments: fos_user.model.user.class
and @doctrine.orm.entity_manager
and your constructor accepts only one (EntityManager
). Just remove first entry from your arguments
list in service definition and you'll be good
Upvotes: 2