Я создал FormType сам. Это должно работать:
<?php
// Baza\BlogBundle\Form\filterType.php
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)
{
//Do something with your Entity Manager using "$this->em"
}
public function getName()
{
return 'filter_type';
}
}
В вашем Диспетчере используют что-то как
<?php
// Baza\BlogBundle\Controller\PageController.php
namespace Baza\BlogBundle\Controller;
use Baza\BlogBundle\Form\filterType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class BaseController extends Controller
{
public function testEntityManager()
{
//assign whatever you need
$enquiry = null;
//getEntityManager() is depricated. Use getManager() instead.
$em = $this->getDoctrine()->getManager();
$this->createForm(
new filterType($em),
$enquiry
);
}
}
Никогда не забывают включать/использовать все классы, которые вы используете. Иначе PHP предположит, что класс в вашем в настоящее время используемом пространстве имен.
Вот почему вы получили ошибку (на посту Серэда)
Catchable Fatal Error: Argument 1 passed to
Baza\BlogBundle\Form\filterType::__construct()
must be an instance of Baza\BlogBundle\Form\EntityManager [...]
Поскольку вы не включали EntityManager PHP, предполагает, что это - класс в вашем текущем пространстве имен, которое было Baza\BlogBundle\Form
.
Забавно выглядящий Класс EntityManager50ecb6f979a07_546a8d27f194334ee012bfe64f629947b07e4919 \__ CG __\Doctrin e\ORM\EntityManager
является прокси-классом Doctrine2.
Since Symfony 2.1, calling $this->getDoctrine()->getEntityManager()
no lonoger results in a Doctrine\ORM\EntityManager
but a proxy class which in fact behaves just like the original EntityManager
and can be passed without problems.