【发布时间】: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% 确定路径设置正常,与数据库的连接正确,我不知道为什么它不起作用。有人可以帮我解决这个问题吗?
【问题讨论】: