Symfony2中的Service DependencyInjection

Paw*_*dej 6 kernel dependency-injection model symfony doctrine-orm

我需要从控制器方法移动我的模型,所以我得到帮助将其更改为服务.服务本身可以工作,但我需要能够从这个服务内部连接到doctrine和kernel.起初我试图启用教义,但这造成了问题.我怎样才能做到这一点?我跟着文档并得到了这段代码.我不知道为什么我得到下面的错误.提前谢谢你的帮助.

我的配置是:

CSVImport.php

namespace Tools\TFIBundle\Model;

use Doctrine\ORM\EntityManager;

class CSVImport  {
    protected $em;

    public function __construct( EntityManager $em ) {
        $this->em = $em;
    }
Run Code Online (Sandbox Code Playgroud)

应用程序/配置/ config.yml

services:
    csvimport:
        class: Tools\TFIBundle\Model\CSVImport
        arguments: [ @doctrine.orm.entity_manager ]
Run Code Online (Sandbox Code Playgroud)

控制器中的动作

$cvsimport = $this->get('csvimport');
Run Code Online (Sandbox Code Playgroud)

我的错误

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
Run Code Online (Sandbox Code Playgroud)

编辑,我的工作代码:

附加了内核的服务类代码

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->em = $em;
        $this->kernel = $k;
}
Run Code Online (Sandbox Code Playgroud)

Eln*_*mov 1

尝试注射@doctrine.orm.default_entity_manager。