Question

This is the function "myList" in ProduitRepository :

    public function myList($id)
{


    $qb = $this->createQueryBuilder('p');

    $qb->where('p.id > 10');

    return $qb->getQuery()
               ->getResult();

}

and this is the builderForm in ProduitType.php :

    public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('nom', 'text',              array('required' => true))
        ->add('description', 'textarea',  array('required' => false))
        ->add('prix', 'money',            array('required' => true))
        ->add('publication', 'checkbox',  array('required' => false))
        ->add('image', new ImageType() )
        ->add('sousCategorie', 'entity',array(
        'class' => 'StoreCategorieBundle:SousCategorie',
        'property' => 'nom',
        'multiple' => false,
        'expanded' => false ))

        ->add('produit', 'entity', array(
        'class' => 'StoreProduitBundle:Produit',
        'property' => 'nom',
        'query_builder' => function(\Store\ProduitBundle\Entity\ProduitRepository $er) {
         return $er->myList();}
         )
    );
}

this is th error message : Expected argument of type "Doctrine\ORM\QueryBuilder", "array" given

Was it helpful?

Solution

In myList() you are not returning a QueryBuilder object, you are returning an array representing the result of the QueryBuilder object. Try switching the return statement in myList($id) to return $qb;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top