如何使用EntityManager作为服务?

时间:2013-01-24 20:06:00

标签: symfony-2.1

我已经查看了2.1版。没做多少现在尝试在服务中使用实体管理器:

<service id="user.manager" class="%user_manager.class%">
    <argument type="service" id="doctrine.orm.entity_manager" />
</service>

但我收到错误:

Catchable fatal error: Argument 1 passed to Doctrine\ORM\EntityManager::__construct()
must be an instance of Doctrine\DBAL\Connection, instance of Doctrine\ORM\EntityManager 
    given, called in C:\Program Files (x86)\Zend\Apache2\htdocs\po\vendor\
    doctrine\orm\lib\Doctrine\ORM\EntityManager.php on line 689 and defined in 
    C:\Program Files (x86)\Zend\Apache2\htdocs\po\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php on line 129

默认配置:

doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

我已经多次这样做了,我不确定我现在缺少什么:(

1 个答案:

答案 0 :(得分:0)

叹息,真棒

app/console doctrine:generate:entities

没有生成我的存储库。我是手工制作的,不小心让它扩展了EntityManager而不是EntityRepository。