【问题标题】:Silex and doctrine orm mapping - no mappings detectedSilex 和教义 orm 映射 - 未检测到映射
【发布时间】:2016-02-27 20:59:43
【问题描述】:

我在 silex 应用程序中设置实体映射时遇到问题。

注册服务:

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
    'db.options' => array(
        'driver'   => 'pdo_mysql',
        'dbname'   => 'blabla',
        'host'     => 'blabla',
        'user'     => 'blabla',
        'password' => 'blabla',
        'port'     => '3306',
        'charset'  => 'utf8'
    ),
));

$app->register(new DoctrineOrmServiceProvider(), [
    'orm.em.options.mappings' => [
            [
                'type' => 'simple_yml',
                'namespace' => 'App\Entities',
                'path' => __DIR__. '/Resources/orm/mappings/',
            ],
    ]
]);

src/Resources/orm/mappings/User.orm.yml

User:
  type: entity
  table: users
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    username:
      type: string
    email:
      type: string
    github_token:
      type: string
    github_token_created_at:
      type: datetimetz
    created_at:
      type: datetimetz
    updated_at:
      type: datetimetz

而实体类本身在:src/Entities/User.php

cli-config.php 文件:

<?php
require_once 'vendor/autoload.php';

$app = require_once 'src/app.php';

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($app['orm.em']);

我正在运行以下命令:

vendor/bin/doctrine orm:info

我收到有关缺少映射的信息:

 [Exception]                                                                                                                                                                            
  You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors`

我 99% 确定路径设置正常,与数据库的连接正确,我不知道为什么它不起作用。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: orm doctrine silex


    【解决方案1】:

    我见过的大多数映射都是这样的

        'mappings' => array(
            // Using actual filesystem paths
            array(
                'type' => 'annotation',
                'namespace' => 'Foo\Entities',
                'path' => __DIR__.'/src/Foo/Entities',
            ),
    

    您的命名空间和路径似乎没有任何显着的关系

    【讨论】:

    • 因为我不使用注释。命名空间用于实体,路径用于 yml 文件所在的位置。
    • 我没有尝试过这种配置。您是否检查过您的自动加载是否正常工作?
    • 自动加载工作正常。我将 $app['orm.em'] 对象转储到 cli-config.php 文件中。有一个例子。没有类未找到消息等。
    • 你能告诉我你用来自动加载的代码行吗?
    • 您能具体说明一下您对自动加载的看法吗?我只是在考虑作曲家一。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    • 2016-10-02
    • 2012-08-17
    • 2017-10-02
    • 1970-01-01
    • 2015-06-30
    相关资源
    最近更新 更多