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

Kor*_*emi 2 mapping orm doctrine 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);

?>
Run Code Online (Sandbox Code Playgroud)

这是我的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);

?>
Run Code Online (Sandbox Code Playgroud)

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

  >  php vendor/doctrine/orm/bin/doctrine orm:convert-mapping xml ./path/to/entities/
Run Code Online (Sandbox Code Playgroud)

Zol*_*üle 7

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

<?php

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

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
Run Code Online (Sandbox Code Playgroud)