Symfony Form Error: "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

gabf Hahn

I have two form inside the Controller the first form works fine however my second Form does not work as expected.

MyController:

// Second Form
$formTwo = $this->get('form.factory')->createNamedBuilder('form2name', new CarType(), null, array())
        ->getForm();

if('POST' === $request->getMethod()) {

if ($request->request->has('form1name')) {
    // handle the first form  
}

if ($request->request->has('form2name')) {
    // handle the second form 
    // get the id value of the selected value. 
  }
}

My CarType:

public function buildForm(FormBuilderInterface $builder, array $options){

   $builder->add('makename','entity',array(
                    'class'=> 'MyTestBundle:Car\CarModel',
                    'query_builder'=>function(EntityRepository $er){
                        return $query = $er->createQueryBuilder('s')
                                    ->select('s.makename')
                                    ->distinct()
                                    ->orderBy('s.makename','ASC');
                }

   ));
  $builder->add('search','submit',array());
}

My Car Entity

Full Stack Trace

Error : "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

Symfony Version : 2.7

Delphine

In query_builder (for building your form) you have to return a QueryBuilder object. Currently, you return a Query object.

Juste remove getQuery()

 $builder->add('makename','entity',array(
                    'class'=> 'MyTestBundle:Car\CarModel',
                    'query_builder'=>function(EntityRepository $er){
                        return $er->createQueryBuilder('s')
                                    ->select('s.makename')
                                    ->distinct()
                                    //->getQuery(); remove this line
                }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Symfony upgrade from 2.2 to 2.3 Expected argument of type "string or Symfony\Component\PropertyAccess\PropertyPath", "boolean" given

From Dev

Symfony Form - Expected argument of type "string or Symfony\Component\Form\FormTypeInterface", "array" given

From Dev

Expected argument of type "array or (\Traversable and \ArrayAccess) in Symfony collection field type

From Dev

Symfony 2.6 "PropertyAccessor" exception: Expected argument of type "object or array", "NULL" given

From Dev

Cannot convert value of type 'String!' to expected argument type error

From Dev

Swift error: cannot convert value of type 'Int32' to expected argument type 'Int32'

From Dev

Expected argument of type "string", "Vendor\NameBundle\Form\EntitynameType" given Symfony 3.0

From Dev

using .filter() in swift: error: cannot convert value of type '([V]) -> Bool' to expected argument type '([_]) -> Bool'

From Dev

Swift Error: Cannot convert value of type 'ArraySlice' to expected argument type

From Dev

Variadic Parameters - Compiler Error cannot convert value of type '[Int]' to expected argument type 'Int'

From Dev

FindBugs Integer not compatible with expected argument type?

From Dev

Cannot convert value of type '()' to expected argument type '() -> ()'

From Dev

VichUploaderBundle- expected argument of type "AppBundle\Entity\File", "Symfony\Component\HttpFoundation\File\UploadedFile" given

From Dev

Expected argument of type "object or array", "integer" given

From Dev

Symfony Form Error: "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

From Dev

Parameter tags value '' violated a constraint (Expected argument of type \"array or Traversable\", \"string\" given)"

From Dev

Error: Cannot convert value of type '(_, _) -> Void' to expected argument type '((UIAlertAction) -> Void)?'

From Dev

SWIFT error "cannot convert a value of type "UIImageView" to expected argument type "UIImage"

From Dev

VichUploaderBundle- expected argument of type "AppBundle\Entity\File", "Symfony\Component\HttpFoundation\File\UploadedFile" given

From Dev

Error 'cannot convert value of type 'int' to expected argument type 'UInt'

From Dev

firebase swift 3 conversion : Cannot convert value of type '(_) -> ()' to expected argument type '((Error) -> Void)?

From Dev

Error: Cannot convert value of type '(_) throws -> ()' to expected argument type '((UIAlertAction) -> Void)?'

From Dev

Error: Cannot convert value of type "[String]" to expected argument type "String?"

From Dev

Symfony "Type" constraint: Expected argument of type "string", "array" given exception

From Dev

EasyAdminBundle and VichUploaderBundle - Error: The expected argument of type"", "Symfony\Component\HttpFoundation\File\UploadedFile" given

From Dev

Symfony Form Error

From Dev

How i can fix this error :Cannot convert value of type 'NSURL' to expected argument type 'URLRequest'

From Dev

error cannot convert value of type `Void` to expected argument type `() -> Void` UIAlertController

From Dev

error: cannot convert value of type 'ObjCBool' to expected argument type 'Bool' on Swift 4.1.2 and Kitura on Ubuntu 16.04

Related Related

  1. 1

    Symfony upgrade from 2.2 to 2.3 Expected argument of type "string or Symfony\Component\PropertyAccess\PropertyPath", "boolean" given

  2. 2

    Symfony Form - Expected argument of type "string or Symfony\Component\Form\FormTypeInterface", "array" given

  3. 3

    Expected argument of type "array or (\Traversable and \ArrayAccess) in Symfony collection field type

  4. 4

    Symfony 2.6 "PropertyAccessor" exception: Expected argument of type "object or array", "NULL" given

  5. 5

    Cannot convert value of type 'String!' to expected argument type error

  6. 6

    Swift error: cannot convert value of type 'Int32' to expected argument type 'Int32'

  7. 7

    Expected argument of type "string", "Vendor\NameBundle\Form\EntitynameType" given Symfony 3.0

  8. 8

    using .filter() in swift: error: cannot convert value of type '([V]) -> Bool' to expected argument type '([_]) -> Bool'

  9. 9

    Swift Error: Cannot convert value of type 'ArraySlice' to expected argument type

  10. 10

    Variadic Parameters - Compiler Error cannot convert value of type '[Int]' to expected argument type 'Int'

  11. 11

    FindBugs Integer not compatible with expected argument type?

  12. 12

    Cannot convert value of type '()' to expected argument type '() -> ()'

  13. 13

    VichUploaderBundle- expected argument of type "AppBundle\Entity\File", "Symfony\Component\HttpFoundation\File\UploadedFile" given

  14. 14

    Expected argument of type "object or array", "integer" given

  15. 15

    Symfony Form Error: "Expected argument of type "Doctrine\ORM\QueryBuilder", "Doctrine\ORM\Query" given"

  16. 16

    Parameter tags value '' violated a constraint (Expected argument of type \"array or Traversable\", \"string\" given)"

  17. 17

    Error: Cannot convert value of type '(_, _) -> Void' to expected argument type '((UIAlertAction) -> Void)?'

  18. 18

    SWIFT error "cannot convert a value of type "UIImageView" to expected argument type "UIImage"

  19. 19

    VichUploaderBundle- expected argument of type "AppBundle\Entity\File", "Symfony\Component\HttpFoundation\File\UploadedFile" given

  20. 20

    Error 'cannot convert value of type 'int' to expected argument type 'UInt'

  21. 21

    firebase swift 3 conversion : Cannot convert value of type '(_) -> ()' to expected argument type '((Error) -> Void)?

  22. 22

    Error: Cannot convert value of type '(_) throws -> ()' to expected argument type '((UIAlertAction) -> Void)?'

  23. 23

    Error: Cannot convert value of type "[String]" to expected argument type "String?"

  24. 24

    Symfony "Type" constraint: Expected argument of type "string", "array" given exception

  25. 25

    EasyAdminBundle and VichUploaderBundle - Error: The expected argument of type"", "Symfony\Component\HttpFoundation\File\UploadedFile" given

  26. 26

    Symfony Form Error

  27. 27

    How i can fix this error :Cannot convert value of type 'NSURL' to expected argument type 'URLRequest'

  28. 28

    error cannot convert value of type `Void` to expected argument type `() -> Void` UIAlertController

  29. 29

    error: cannot convert value of type 'ObjCBool' to expected argument type 'Bool' on Swift 4.1.2 and Kitura on Ubuntu 16.04

HotTag

Archive