Note that there are some explanatory texts on larger screens.

plurals
  1. POService DependencyInjection in Symfony2
    primarykey
    data
    text
    <p>I needed to move my model from the controller method, so I got help to change it to a service. The service by itself works, but I need to be able to connect to doctrine and the kernel from inside of this service. At first I tried to enable doctrine, but that created problems. How can I make this work? I've followed docs and got this code. I have no idea why I got the error below. Thank you for your help in advance.</p> <p>My config is:</p> <p><strong>CSVImport.php</strong></p> <pre><code>namespace Tools\TFIBundle\Model; use Doctrine\ORM\EntityManager; class CSVImport { protected $em; public function __construct( EntityManager $em ) { $this-&gt;em = $em; } </code></pre> <p><strong>app/config/config.yml</strong></p> <pre><code>services: csvimport: class: Tools\TFIBundle\Model\CSVImport arguments: [ @doctrine.orm.entity_manager ] </code></pre> <p><strong>action in controller</strong></p> <pre><code>$cvsimport = $this-&gt;get('csvimport'); </code></pre> <p><strong>MY ERROR</strong></p> <pre><code>Catchable Fatal Error: Argument 1 passed to Tools\TFIBundle\Model\CSVImport::__construct() must be an instance of Doctrine\ORM\EntityManager, none given, called in .../Tools/TFIBundle/Controller/DefaultController.php on line 58 and defined in .../Tools/TFIBundle/Model/CSVImport.php line 12 </code></pre> <p>EDIT, my working code:</p> <p><strong>service class code with Kernel attached to it</strong></p> <pre><code>namespace Tools\TFIBundle\Model; use Doctrine\ORM\EntityManager, AppKernel; class CSVImport { protected $em; protected $kernel; protected $cacheDir; public function __construct( EntityManager $em, AppKernel $k ) { $this-&gt;em = $em; $this-&gt;kernel = $k; } </code></pre>
    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. 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