Doctrine文档中有关于Setting up the Commandline Tool
的部分您需要将应用程序EntityManager注册到控制台 通过创建cli-config.php来使用任务的工具
所以在我的训练中我得到了:
// core/Cms.php
private function __construct() {
$loader = require __DIR__ . '/../../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$paths = array(ENTITY_DIR);
$isDevMode = false;
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => DB_SERVER,
'port' => DB_PORT,
'user' => DB_USER,
'password' => DB_PASSWORD,
'dbname' => DB_NAME,
'charset' => 'utf8',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
$config->setProxyDir(CLASS_DIR . '/Proxies');
$config->setProxyNamespace('Application\Classes\Proxies');
$config->setAutoGenerateProxyClasses(Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS);
$entityManager = EntityManager::create($dbParams, $config);
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
self::$entityManager = $entityManager;
}
并在同一项目目录core / cli-config.php中:
// core/cli-config.php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
require(SYS_DIR . '/core/Cms.php'); // my bootstrap
Cms::initialize();
$entityManager = Cms::$entityManager;
return ConsoleRunner::createHelperSet($entityManager);
然后命令php vendor/bin/doctrine --help
显示:
您缺少“cli-config.php”或“config / cli-config.php”文件 您的项目,这是使Doctrine控制台正常工作所必需的。
答案 0 :(得分:-1)
使用:
vendor/bin/doctrine --help
代替:
php vendor/bin/doctrine --help