使用 Silex 的命令行 Doctrine ORM:您的项目中缺少 "cli-config.php" 或 "config/cli-config.php" 文件
Command line Doctrine ORM with Silex: You are missing a "cli-config.php" or "config/cli-config.php" file in your project
我正在尝试将 Doctrine ORM 与 Silex 一起使用,但由于缺乏一致的文档,我发现这是一种完全令人沮丧的体验。
当我在控制台 运行 vendor/bin/doctrine
时,我得到以下输出:
输出:
You are missing a "cli-config.php" or "config/cli-config.php" file in your
project, which is required to get the Doctrine Console working. You can use the
following sample as a template:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
这是我的 composer.json 文件:
{
"require": {
"silex/silex": "2.0.*@dev",
"symfony/yaml": "2.6.7",
"doctrine/dbal": "~2.2",
"dflydev/doctrine-orm-service-provider": "2.0.*@dev",
"khepin/yaml-fixtures-bundle": "~0.8.1"
},
"config": {
"bin-dir": "bin"
}
}
这是注册Doctrine服务等的php代码
<?php
use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ArrayCache;
use Silex\Provider\DoctrineServiceProvider;
use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
$app->register(new DoctrineServiceProvider(), array(
'db.options' => array(// http://silex.sensiolabs.org/doc/providers/doctrine.html
'driver' => 'pdo_mysql',
'dbname' => 'foobar',
'host' => 'localhost',
'user' => 'root',
'password' => 'root',
'charset' => 'utf8'
)
));
$app->register(new DoctrineORMServiceProvider(),
array(
'db.orm.proxies_dir' => __DIR__.'/../cache/doctrine/proxy',
'db.orm.proxies_namespace' => 'DoctrineProxy',
'db.orm.cache' => !$app['debug'] &&extension_loaded('apc') ? new ApcCache() : new ArrayCache(),
'db.orm.auto_generate_proxies' => true,
'db.orm.entities' => array(array(
'type' => 'simple_yaml',
'path' => __DIR__.'/src/Resources/config/doctrine',
'namespace' => 'Foobar\Entity',
)),
));
这是我的配置文件(bin/cli-config.php)
<?php
// retrieve EntityManager
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$app = require_once __DIR__.'/../app/src/app.php';
$isDevMode = $app['debug'];
$paths = $app['db.orm.entities']['path'];
$config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($app['db.options'], $config);
return ConsoleRunner::createHelperSet($entityManager);
我做错了什么?
您需要将 bin/cli-config.php
移动到 config/cli-config.php
。
很遗憾,我没有找到有关它的文档。我打开了 doctrine/dbal/bin/doctrine-dbal.php
并检查了它是如何工作的。
cli-config.php 和 bootstrap.php 都应该放在 同一个文件夹中。如果我将它们放在我的 zend 项目的根目录或 root->config 文件夹中,它们就会为我工作。
然后 orm:convert-mac 终端中的映射命令成功运行。
./vendor/bin/doctrine orm:convert-mapping --namespace="Quiz\Model\Entity" --force --from-database annotation ./module/Quiz/src/Model/
我正在尝试将 Doctrine ORM 与 Silex 一起使用,但由于缺乏一致的文档,我发现这是一种完全令人沮丧的体验。
当我在控制台 运行 vendor/bin/doctrine
时,我得到以下输出:
输出:
You are missing a "cli-config.php" or "config/cli-config.php" file in your
project, which is required to get the Doctrine Console working. You can use the
following sample as a template:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
这是我的 composer.json 文件:
{
"require": {
"silex/silex": "2.0.*@dev",
"symfony/yaml": "2.6.7",
"doctrine/dbal": "~2.2",
"dflydev/doctrine-orm-service-provider": "2.0.*@dev",
"khepin/yaml-fixtures-bundle": "~0.8.1"
},
"config": {
"bin-dir": "bin"
}
}
这是注册Doctrine服务等的php代码
<?php
use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ArrayCache;
use Silex\Provider\DoctrineServiceProvider;
use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
$app->register(new DoctrineServiceProvider(), array(
'db.options' => array(// http://silex.sensiolabs.org/doc/providers/doctrine.html
'driver' => 'pdo_mysql',
'dbname' => 'foobar',
'host' => 'localhost',
'user' => 'root',
'password' => 'root',
'charset' => 'utf8'
)
));
$app->register(new DoctrineORMServiceProvider(),
array(
'db.orm.proxies_dir' => __DIR__.'/../cache/doctrine/proxy',
'db.orm.proxies_namespace' => 'DoctrineProxy',
'db.orm.cache' => !$app['debug'] &&extension_loaded('apc') ? new ApcCache() : new ArrayCache(),
'db.orm.auto_generate_proxies' => true,
'db.orm.entities' => array(array(
'type' => 'simple_yaml',
'path' => __DIR__.'/src/Resources/config/doctrine',
'namespace' => 'Foobar\Entity',
)),
));
这是我的配置文件(bin/cli-config.php)
<?php
// retrieve EntityManager
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$app = require_once __DIR__.'/../app/src/app.php';
$isDevMode = $app['debug'];
$paths = $app['db.orm.entities']['path'];
$config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($app['db.options'], $config);
return ConsoleRunner::createHelperSet($entityManager);
我做错了什么?
您需要将 bin/cli-config.php
移动到 config/cli-config.php
。
很遗憾,我没有找到有关它的文档。我打开了 doctrine/dbal/bin/doctrine-dbal.php
并检查了它是如何工作的。
cli-config.php 和 bootstrap.php 都应该放在 同一个文件夹中。如果我将它们放在我的 zend 项目的根目录或 root->config 文件夹中,它们就会为我工作。
然后 orm:convert-mac 终端中的映射命令成功运行。
./vendor/bin/doctrine orm:convert-mapping --namespace="Quiz\Model\Entity" --force --from-database annotation ./module/Quiz/src/Model/