我在使用silex app设置实体映射时遇到问题。
注册服务:
$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 /资源/ ORM /映射/ 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%确定路径设置正常,与数据库的连接是正确的,我不知道为什么它不起作用。有人可以帮我这个吗?
答案 0 :(得分:0)
我见过的大多数映射都是这样的
'mappings' => array(
// Using actual filesystem paths
array(
'type' => 'annotation',
'namespace' => 'Foo\Entities',
'path' => __DIR__.'/src/Foo/Entities',
),
您似乎没有任何显着关系中的命名空间和路径