/Edited/
I have this class:
namespace Baza\BlogBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityManager;
class filterType extends AbstractType
{
protected $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->$em->getDoctrine()->getEntityManager();
/****
****/
}
}
And this is my services yml:
services:
filterType:
class: Baza\BlogBundle\Form\filterType
arguments: [doctrine.orm.entity_manager]
When I run the code I get following exception:
Catchable Fatal Error: Argument 1 passed to Baza\BlogBundle\Form\filterType::__construct() must be an instance of Doctrine\ORM\EntityManager, none given
I’m all out of ideas.
I created the FormType myself. This should work:
In your Controller use something like
Never forget to include/use all the classes you are using. Otherwise PHP will assume the class is inside your currently used namespace.
That’s why you got the error (on Cerad’s post)
As you didn’t include the EntityManager PHP assumes it’s a class inside your current namespace which was
Baza\BlogBundle\Form.The funny looking Class
EntityManager50ecb6f979a07_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManageris a Doctrine2 proxy class.Since Symfony 2.1, calling
$this->getDoctrine()->getEntityManager()no lonoger results in aDoctrine\ORM\EntityManagerbut a proxy class which in fact behaves just like the originalEntityManagerand can be passed without problems.