Silex和Doctrine2:YML实体找不到类

时间:2016-10-30 18:09:33

标签: php orm doctrine-orm composer-php silex

我通过Doctrine ORM Service Provider在Silex中使用Doctrine ORM,但每次尝试从实体加载数据时,我都会收到一个“异常不存在”的MappingException。

例外:

MappingException in MappingException.php line 96: Class 'Project\Database\Mappings\Users' does not exist

文件结构:

.
├───App
│   ├───Config
│   ├───Controllers
│   ├───Logs
│   └───Views
├───Doctrine
│   ├───Mappings
│   └───Repositories

我的实体位于Doctrine\Mappings,定义为

Project\Database\Mappings\Users:
  type: entity
  repositoryClass: Project\Database\Repositories\UsersRepository
  table: users
  schema: transcribe
  id: [...]
  fields: [...]

我的服务注册如此(位于App/init.php):

// Register Doctrine ORM service
$app->register(new DoctrineOrmServiceProvider, [
    'orm.em.options' => [
        'mappings' => [
            [
                'type' => 'simple_yml',
                'namespace' => 'Project\Database\Mappings',
                'path' => __DIR__ . "/../Doctrine/Mappings",
            ]
        ]
    ],
]);

在我的样本控制器(App/Controllers/HomeController.php)中,

class HomeController
{
    protected $twig;
    protected $repo;

    public function __construct(Twig_Environment $twig, EntityManager $em)
    {
        $this->twig = $twig;
        $this->repo = $em->getRepository("Project\Database\Mappings\Users");
    }
}

我的路线是为了完成(App/routes.php):

use Project\App\Controllers\HomeController;

// Register controllers
$app['home.controller'] = function () use ($app) {
    return new HomeController($app['twig'], $app['orm.em']);
};

// Define routes
$app->get("/", "home.controller:index");

我确实在composer.json中设置了自动加载器配置:

"autoload": {
    "psr-4": {
        "Project\\App\\": "App",
        "Project\\Database\\": "Doctrine"
    }
}

我无法在Doctrine或服务提供商文档中找到任何声明我必须做任何特殊事情以使YAML实体工作的内容。

0 个答案:

没有答案