设置Doctrine控制台时找不到致命错误HelperSet(使用CodeIgniter)

时间:2015-03-06 11:12:28

标签: php codeigniter doctrine-orm doctrine

我在使用CodeIgniter设置Doctrine时遇到了问题。运行时出现以下错误:

Fatal error: Class 'Symfony\Component\Console\Helper\HelperSet' not found in /Applications/MAMP/htdocs/CodeIgniter-2.2.1/application/doctrine.php on line 21

文件夹结构如下所示

/application/
/application/doctrine.php
/application/libraries/
/application/libraries/Doctrine/
/application/libraries/Doctrine/Common
/application/libraries/Doctrine/DBAL
/application/libraries/Doctrine/ORM
/application/libraries/Doctrine/Symfony
/application/libraries/Doctrine/Doctrine.php
/application/libraries/Doctrine/index.html

这是第21行

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));

无法找出问题所在..

遵循本教程:http://wildlyinaccurate.com/integrating-doctrine-2-with-codeigniter-2/

update这是我在应用程序文件夹中的doctrine.php

<?php

define('APPPATH', dirname(__FILE__) . '/');
define('BASEPATH', APPPATH . '/../system/');
define('ENVIRONMENT', 'development');

chdir(APPPATH);

require __DIR__ . '/libraries/Doctrine.php';

foreach ($GLOBALS as $helperSetCandidate) {
    if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
        $helperSet = $helperSetCandidate;
        break;
    }
}

$doctrine = new Doctrine;
$em = $doctrine->em;

$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));

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

2 个答案:

答案 0 :(得分:2)

刚刚下载了github version而没有任何额外设置{@ 3}}。

答案 1 :(得分:0)

检查HelperSet.php目录中是否存在Doctrine/Symfony/Component/Console/Helper文件,并将这些行添加到Doctrine.php目录中的libraries(您必须注册Symfony类):

$symfonyClassLoader = new ClassLoader('Symfony',  APPPATH.'your_path_to/Doctrine');
$symfonyClassLoader->register();

This GitHub repository适用于CodeIgniter 2,请勿使用它。 试试this tutorial,即使对于CI 3,它也适用于我。