Symfony:在链配置的名称空间中找不到类XYZ

时间:2019-03-12 09:13:16

标签: symfony

现有问题没有帮助。 我仍在学习Symfony并建立一个现有项目。尝试从我的应用程序目录中运行主义治安。

./app/console doctrine:fixtures:load --env test

运行它会给我以下错误

  

运行命令“ doctrine:fixtures:load --env test --em default”时抛出错误。消息:“在链配置的名称空间_XyzProjectName \ CalendarContext \ Domain \ Model,Integration \ GetFeedbackBundle \ Model,_XyzProjectName \ AccountingProcessContext \ Domain \ Model,_XyzProjectName \ CaseContext \ Domain中找不到类'ClientPortal \ GenericBundle \ Document \ Accountant' {“ exception”:“ [对象](Doctrine \ Common \ Persistence \ Mapping \ MappingException(代码:0):类'ClientPortal \ GenericBundle \ Document \ Accountant'在链配置的命名空间_XyzProjectName \ CalendarContext \ Domain \中未找到模型,Integration \ GetFeedbackBundle \模型,_XyzProjectName \ AccountingProcessContext \ Domain \ Model,_XyzProjectName \ CaseContext \ Domain位于/ usr / local / var / www / 1800-api / vendor / doctrine / persistence / lib / Doctrine / Common / Persistence / Mapping /MappingException.php:22)

并且试图持久化类的对象时会抛出此异常

  

'ClientPortal \ GenericBundle \ Document \ Accountant'

这是我在config.yml中的学说

doctrine:
dbal:
    driver:   pdo_pgsql
    host:     '%database_host%'
    dbname:   '%database_name%'
    user:     '%database_user%'
    password: '%database_password%'
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true
    mappings:
        CalendarBundle:
            prefix: '_XyzProjectName\CalendarContext\Domain\Model'
        IntegrationGetFeedbackBundle:
            prefix: 'Integration\GetFeedbackBundle\Model'
        AccountingProcessBundle:
            prefix: '_XyzProjectName\AccountingProcessContext\Domain\Model'
        CaseBundle:
            prefix: '_XyzProjectName\CaseContext\Domain'
        GenericBundle:
            type: "annotation"   
            prefix: 'ClientPortal\GenericBundle\Document'
            dir: 'src'
            is_bundle: false

引发此异常的代码段

    $account = new ClientPortal\GenericBundle\Document\Accountant();//full namespace added for clarity - also this file lies in the same directory structure. 
    $account->setSfAccountantId($accountantId);
    $account->setUsername($username);
    $manager = new ObjectManager;
    $manager->persist( $account ); //This throws the above mentioned exception

我的想法是,文件ClientPortal \ GenericBundle \ Document \ Accountant.php正在自动加载,因为在实例化对象时没有引发异常。但是,配置或映射缺少某些内容,因为这些原则不知道如何持久保留其对象。

[源代码] [1]会计类

在AppKernel下注册的GenericBundle

new Website\GenericBundle\WebsiteGenericBundle(),
new Admin\GenericBundle\AdminGenericBundle(),
new ClientPortal\GenericBundle\ClientPortalGenericBundle(),
new TaxApp\GenericBundle\TaxAppGenericBundle(),

2 个答案:

答案 0 :(得分:1)

因此,正如我在评论中建议的那样-尝试将ClientPortal\GenericBundle\Document\命名空间添加到您的理论配置文件中的映射中,如下所示:

#...
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    mappings:
        # ...
        ClientPortalGenericBundle:
            type: annotation
            prefix: 'ClientPortal\GenericBundle\Document\'
            dir: '%kernel.root_dir%/src/ClientPortal/GenericBundle/Document/'
            #is_bundle: false
    auto_mapping: true

答案 1 :(得分:0)

使用多个数据库连接时,Symfony 4遇到相同的问题。这个https://stackoverflow.com/a/55361742/2540699帮助我解决了问题。