我想创建一个项目,我想使用Doctrine 2.我通过Composer安装它。我阅读了文档并在我的根目录中创建了“bootstrap.php”和“cli-config.php”,就像文档所说的那样,但是当我想运行cli时(例如:doctrine orm:schema-tool:create)它说我的cli-config.php文件丢失了。
这是我的项目结构:
doctrine_test
-- config
----(empty)
-- src
----(empty)
-- vendor (my composer vendor)
-- bootstrap.php
-- cli-config.php
-- composer.lock
-- composer.json
我的作曲家档案:
{
"name": "serdartpkl/doctrine_test",
"type": "project",
"authors": [
{
"name": "Serdar Tepekule",
"email": "serdartpkl@gmail.com"
}
],
"require": {
"doctrine/orm": "2.4.*",
"symfony/yaml": "2.*"
},
"autoload": {
"psr-0": {
"": "src/"
}
}
}
我的bootstrap.php文件:
<?php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
我的cli-config.php文件:
<?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);
我知道这是一个蹩脚的问题,但我花了3个小时来解决这个问题。我使用CMD,我试图运行学说cli,如:
C:\>cd xampp/htdocs/doctrine_test
C:\xampp\htdocs\doctrine_test>cd vendor/bin
C:\xampp\htdocs\doctrine_test\vendor\bin>doctrine orm:schema-tool:create
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);
感谢您的回答。