2016-09-30 60 views
1

我试图让我的学说命令行工具中的Symfony 2项目工作在Windows 7和我不断收到在控制台同样的错误信息:Symfony的2学说2 EntityManager的配置

我CLI-的
Fatal error: Call to protected Doctrine\ORM\EntityManager::__construct() 
from invalid context in C:\wamp\www\firstSymfonyApp\cli-config.php on line 9 

Call Stack: 
0.0010  239440 1. {main}() C:\wamp\www\firstSymfonyApp\vendor\doctrine\orm\bin\doctrine.php:0 
0.0090  621376 2. require('C:\wamp\www\firstSymfonyApp\cli-config.php') C:\wamp\www\firstSymfonyApp\vendor\doctrine\orm\bin\doctrine.php:48 

代码config.php文件:今天

<?php 
use Doctrine\ORM\Tools\Console\ConsoleRunner; 
require_once 'app/bootstrap.php.cache'; 
$em = new \Doctrine\ORM\EntityManager(); 
return ConsoleRunner::createHelperSet($em); 

直到,我只是在Linux上使用学说在安装是更简单,请大家帮我来解决这一问题。

+0

我相当有信心,你上面贴的代码也没有在Linux上工作。按照这个:http://docs.doctrine-project.org/en/latest/tutorials/getting-started.html并使用$ entityManager = EntityManager :: create($ conn,$ config); – Cerad

回答

0

错误信息非常明确。 EntityManager::__constructprotected方法,所以你不能在课堂外使用它。

结账EntityManager::create

检查this link有关如何使用Doctrine 2

启动的更多信息,这可能是这应该是对你很重要,现在的片段:

<?php 
// bootstrap.php 
require_once "vendor/autoload.php"; 

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

$paths = array("/path/to/entity-files"); 
$isDevMode = false; 

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

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); 
$entityManager = EntityManager::create($dbParams, $config); 
+0

我已经在我的引导文件中使用了这段代码,唯一错误的是$ em = new \ Doctrine \ ORM \ EntityManager();而不是$ em = $ entityManager;在我的cli-config文件中。无论如何,谢谢你。还有一个更愚蠢的问题:我应该在哪个boostrap.php文件中存储粘贴的代码?我把它放在我的bootstrap.php.cache文件中,但它可能是错误的。 –

+0

实际上,在使用Symfony时,您不需要自己创建一个EntityManager。这一切都是由服务完成的。 –