2016-09-30 59 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。這一切都是由服務完成的。 –