Fatal error HelperSet not found when setting up Do

2019-07-20 22:54发布

问题:

I've got a problem setting up Doctrine with CodeIgniter. When running the following error is coming up:

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

The folder structure looks like this

/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

This is the line 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)
));

Cannot find out what is the problem..

Followed this tutorial: http://wildlyinaccurate.com/integrating-doctrine-2-with-codeigniter-2/

update This is my doctrine.php in the application folder

<?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);

回答1:

Just downloaded github version and without any extra settings everything seems to be ok.



回答2:

Check if the HelperSet.php file exists in Doctrine/Symfony/Component/Console/Helper directory, and add these lines to Doctrine.php in libraries directory (you have to register Symfony classes):

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

This GitHub repository is for CodeIgniter 2, don't use it. Try this tutorial, it works fine for me, even for CI 3.