Symfony2: Undefined method: getDoctrine()

krystah

I am very new to Symfony2 and can't seem to wrap my head around this issue. When executing an action, I am receiving this error:

Call to undefined method: getDoctrine()

Controller:

public function createAction() {

  $string = new FrontendString();
  $string->setStringval("Hayaku!");

  $em = $this->getDoctrine()->getManager();
  $em->persist($string);
  $em->flush();

  return new Response('Created string with id '. $string->getId());
}

The Entity file has all its generated getters and setters according to correct annotations. I have no Repository or Model folder. Am I missing something obvious?

Alexey B.

Make sure your controller extends Symfony\Bundle\FrameworkBundle\Controller\Controller, read about it in documentation

For convenience, Symfony2 comes with a base Controller class that assists with some of the most common controller tasks and gives your controller class access to any resource it might need. By extending this Controller class, you can take advantage of several helper methods.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Symfony2 - Setting up service error with undefined getDoctrine()

From Dev

Attempted to call method "getDoctrine" on class (Symfony)

From Dev

Undefined method 'getDoctrine'. The method name must start with either findBy or findOneBy

From Dev

Symfony2 and Doctrine entity undefined method

From Dev

Symfony2 and Doctrine entity undefined method

From Dev

Symfony2 getdoctrine outside of Model/Controller

From Dev

getDoctrine() not working in FOSUserBundle symfony2

From Dev

Symfony2 getdoctrine outside of Model/Controller

From Dev

Attempted to call method "getDoctrine" on class "Symfony\Component\HttpFoundation\Response"

From Dev

Symfony2: Call to undefined method Doctrine\ORM\QueryBuilder::getResult()

From Dev

Symfony2 Sylius CartBundle setVariant method undefined

From Dev

Symfony2: Call to undefined method Doctrine\ORM\QueryBuilder::getResult()

From Dev

Symfony2 - Fatal error: Call to undefined method Symfony\Bundle\DoctrineBundle\Registry::getManager()

From Dev

Symfony2 custom Voter: cannot have access to getDoctrine from inside the Voter

From Dev

Symfony2 Undefined variable: handleRequest

From Dev

Symfony2 undefined service parameter

From Dev

Managing permissions method in Symfony2

From Dev

Symfony2 : Add method to an Entity

From Dev

Symfony2 toString() method with multiple variables

From Dev

toString method for SonataAdminBundle Listing in Symfony2

From Dev

Symfony2 - Factory method in collection form

From Dev

Symfony2 toString() method with multiple variables

From Dev

Symfony2 method with query in entity

From Dev

Symfony2 + Propel Collection undefined offset: 2

From Dev

Undefined Variable "name" in Enquiry.php (Symfony2)

From Dev

Undefined variable about the Uploader File with symfony2

From Dev

Validate the form if it is null/undefined using a twig form in symfony2

From Dev

Symfony2 : Undefined Function "ftp_ssl_connect"

From Dev

Symfony2 form - setParameter claims that the variable is undefined

Related Related

  1. 1

    Symfony2 - Setting up service error with undefined getDoctrine()

  2. 2

    Attempted to call method "getDoctrine" on class (Symfony)

  3. 3

    Undefined method 'getDoctrine'. The method name must start with either findBy or findOneBy

  4. 4

    Symfony2 and Doctrine entity undefined method

  5. 5

    Symfony2 and Doctrine entity undefined method

  6. 6

    Symfony2 getdoctrine outside of Model/Controller

  7. 7

    getDoctrine() not working in FOSUserBundle symfony2

  8. 8

    Symfony2 getdoctrine outside of Model/Controller

  9. 9

    Attempted to call method "getDoctrine" on class "Symfony\Component\HttpFoundation\Response"

  10. 10

    Symfony2: Call to undefined method Doctrine\ORM\QueryBuilder::getResult()

  11. 11

    Symfony2 Sylius CartBundle setVariant method undefined

  12. 12

    Symfony2: Call to undefined method Doctrine\ORM\QueryBuilder::getResult()

  13. 13

    Symfony2 - Fatal error: Call to undefined method Symfony\Bundle\DoctrineBundle\Registry::getManager()

  14. 14

    Symfony2 custom Voter: cannot have access to getDoctrine from inside the Voter

  15. 15

    Symfony2 Undefined variable: handleRequest

  16. 16

    Symfony2 undefined service parameter

  17. 17

    Managing permissions method in Symfony2

  18. 18

    Symfony2 : Add method to an Entity

  19. 19

    Symfony2 toString() method with multiple variables

  20. 20

    toString method for SonataAdminBundle Listing in Symfony2

  21. 21

    Symfony2 - Factory method in collection form

  22. 22

    Symfony2 toString() method with multiple variables

  23. 23

    Symfony2 method with query in entity

  24. 24

    Symfony2 + Propel Collection undefined offset: 2

  25. 25

    Undefined Variable "name" in Enquiry.php (Symfony2)

  26. 26

    Undefined variable about the Uploader File with symfony2

  27. 27

    Validate the form if it is null/undefined using a twig form in symfony2

  28. 28

    Symfony2 : Undefined Function "ftp_ssl_connect"

  29. 29

    Symfony2 form - setParameter claims that the variable is undefined

HotTag

Archive