Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I created the FormType myself. This should work:</p> <pre><code>&lt;?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-&gt;em = $em; } public function buildForm(FormBuilderInterface $builder, array $options) { // Do something with your Entity Manager using "$this-&gt;em" } public function getName() { return 'filter_type'; } } </code></pre> <p>In your Controller use something like</p> <pre><code>&lt;?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-&gt;getDoctrine()-&gt;getManager(); $this-&gt;createForm( new filterType($em), $enquiry ); } } </code></pre> <p><strong>Never forget to include/use all the classes you are using. Otherwise PHP will assume the class is inside your currently used namespace.</strong></p> <p>That's why you got the error (on Cerad's post)</p> <pre><code>Catchable Fatal Error: Argument 1 passed to Baza\BlogBundle\Form\filterType::__construct() must be an instance of Baza\BlogBundle\Form\EntityManager [...] </code></pre> <p>As you didn't include the EntityManager PHP assumes it's a class inside your current namespace which was <code>Baza\BlogBundle\Form</code>.</p> <hr> <p>The funny looking Class <code>EntityManager50ecb6f979a07_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrin‌​e\ORM\EntityManager</code> is a Doctrine2 proxy class.</p> <p>Since Symfony 2.1, calling <code>$this-&gt;getDoctrine()-&gt;getEntityManager()</code> no lonoger results in a <code>Doctrine\ORM\EntityManager</code> but a proxy class which in fact behaves just like the original <code>EntityManager</code> and can be passed without problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload