php - Get doctrine outside controller -


i tried doctrine outside controller goes wrong , don't understand why.

so created service :

services:     doctrine.service:         class: app\desktopbundle\lib\doctrineservice         arguments: [ "@doctrine.orm.entity_manager" ] 

and doctrineservice file :

namespace app\desktopbundle\lib;  use doctrine\orm\entitymanager;  class doctrineservice {   protected $manager;    public function __construct(entitymanager $manager)   {     $this->manager = $manager;   } } 

and want doctrine in file :

namespace app\desktopbundle\lib\game;  use app\desktopbundle\entity\onelevelhistory; use app\desktopbundle\lib\doctrineservice; use symfony\component\yaml\yaml; use doctrine\orm\entitymanager;  class onelevel{ } 

but don't know how call service created before. can me please?

why didn't inject orm entity manager directly in onelevel class?

//services.yml services:     one_level.service:         class: app\desktopbundle\lib\game\onelevel         arguments: [ "@doctrine.orm.entity_manager" ]   //app\desktopbundle\lib\game\onelevel.php namespace app\desktopbundle\lib\game;  use doctrine\orm\entitymanager; /* other class need */  class onelevel {     /* @var doctrine\orm\entitymanager $em */     protected $em;      /**      * onelevel constructor      *      * @param entitymanager $em      */     public function __construct(entitymanager $em)     {         $this->em = $em;     }      // rest of method ...      public function examplemethod()     {          /.../           $this->em->flush();           /.../     } } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -