在cli-config.php中调用GetEntityManager()中的未定义函数

时间:2014-06-29 16:21:44

标签: orm doctrine mapping entitymanager undefined-function

我尝试从作曲家安装doctrine2 orm,它是成功的,我设置了我的bootstrap.php,如下所示

<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__FILE__)));
// bootstrap.php
require_once "vendor/autoload.php";

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$paths = array(ROOT.DS.'library'.DS.'doctrine/entities/');
$isDevMode = false;

// the connection configuration
$dbParams = array(
'driver'   => 'pdo_mysql',
'user'     => 'root',
'password' => '',
'dbname'   => 'meso',
);

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $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);

?>

当我尝试使用cli下面的命令创建orm映射到我的实体文件夹时,它会抛出此错误“在第8行的cli-config.php中调用GetEntityManager()中的未定义函数”

  >  php vendor/doctrine/orm/bin/doctrine orm:convert-mapping xml ./path/to/entities/

2 个答案:

答案 0 :(得分:5)

仅将此代码放入cli-config.php就足够了,因为您已经定义了$entityManager并在引导程序中为其分配了值。

<?php

// cli-config.php
require_once "bootstrap.php";

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);

答案 1 :(得分:1)

我发现了我的问题的解决方案,我还没有创建一个调用EntityManager实例的getEntitymanager函数。我在bootstrap.php中做到了这一点