Doctrine默认cli-config.php位置

时间:2015-06-08 02:15:54

标签: doctrine-orm command-line-interface

我想更改doctrine cli-config.php文件的位置以及可能更改它的名称 - 第一个请求更重要。

任何想法???

2 个答案:

答案 0 :(得分:2)

如果您直接使用doctrine CLI,则无法实现。

您可以通过查看相关的source code

来看到这一点
$directories = array(getcwd(), getcwd() . DIRECTORY_SEPARATOR . 'config');
$configFile = null;
foreach ($directories as $directory) {
    $configFile = $directory . DIRECTORY_SEPARATOR . 'cli-config.php';
    if (file_exists($configFile)) {
        break;
    }
}

它只检查cli-config.phpconfig/cli-config.php

另一种方法是自己实现基于Symfony Console component(这是Doctrine CLI所基于的)的CLI,并引入Doctrine命令。这样可以避免以cli-config.php为代价,不得不付出不小的工作量。您可以在this answer

中找到此方法的详细信息

答案 1 :(得分:0)

存在另一种方法。您可以添加自定义位置文件,例如cli.php(具有自己的文件名)。比在此文件中添加以下内容:

```

<?php
// cli.php
// where your entityManager is created
require_once "bootstrap.php";

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)
));

\Doctrine\ORM\Tools\Console\ConsoleRunner::run($helperSet);

```

您可以从php cli.php之类的位置运行此文件。