"Class not found"尝试在 ZF2 / 学说下的实体之间创建继承时



在Zend Framework 2下的一个项目中,我有一组带有Doctrine 2注释的实体。当我尝试使用生成模式时

php vendor/bin/doctrine orm:schema-tool:update --force

或者当我尝试使用生成getter/setter时

php vendor/bin/doctrine orm:generate-entities --update-entities="true" --generate-methods="true" module/Application/src

我总是得到这个错误:

PHP Fatal error:  Class 'ApplicationModelEntityCapteur' not found in /home/...MyApp/module/Application/src/Application/Model/Entity/CapteurResident.php on line 9

这里是完整的堆栈:

PHP Fatal error:  Class 'ApplicationModelEntityCapteur' not found in /home/...MyApp/module/Application/src/Application/Model/Entity/CapteurResident.php on line 9
PHP Stack trace:
PHP   1. {main}() /home/...MyApp/vendor/doctrine/orm/bin/doctrine:0
PHP   2. include() /home/...MyApp/vendor/doctrine/orm/bin/doctrine:4
PHP   3. DoctrineORMToolsConsoleConsoleRunner::run() /home/...MyApp/vendor/doctrine/orm/bin/doctrine.php:59
PHP   4. SymfonyComponentConsoleApplication->run() /home/...MyApp/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php:64
PHP   5. SymfonyComponentConsoleApplication->doRun() /home/...MyApp/vendor/symfony/console/Symfony/Component/Console/Application.php:126
PHP   6. SymfonyComponentConsoleApplication->doRunCommand() /home/...MyApp/vendor/symfony/console/Symfony/Component/Console/Application.php:195
PHP   7. SymfonyComponentConsoleCommandCommand->run() /home/...MyApp/vendor/symfony/console/Symfony/Component/Console/Application.php:874
PHP   8. DoctrineORMToolsConsoleCommandSchemaToolAbstractCommand->execute() /home/...MyApp/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
PHP   9. DoctrineCommonPersistenceMappingAbstractClassMetadataFactory->getAllMetadata() /home/...MyApp/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:59
PHP  10. DoctrineCommonPersistenceMappingDriverAnnotationDriver->getAllClassNames() /home/...MyApp/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:113
PHP  11. require_once() /home/...MyApp/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:237

CapterResident和CapterEmbarque是以完全相同的方式扩展Capteur的两个实体。

<?php
namespace ApplicationModelEntity;
use DoctrineORMMapping AS ORM;
/**
 * @ORMEntity
 */
class CapteurResident extends ApplicationModelEntityCapteur
{
/**
 * @ORMEntity
 */
class CapteurEmbarque extends ApplicationModelEntityCapteur
{

如果我删除实体"CapteurResident",一切都很好!

Entity classes generated to "/home/...MyApp/module/Application/src".

但不是在开发服务器上:在这个服务器上,我在另一个继承关系上有错误。。。尽管除了数据库参数之外,一切都是一样的。我真的不明白为什么这个错误在一台机器和另一台机器上发生得不同,为什么有些继承有效,而另一些则无效。

PHP Fatal error:  Class 'ApplicationModelEntityMesure' not found in /home/.../module/Application/src/Application/Model/Entity/MesureCapteurEmbarque.php on line 9

这里的船长类:

<?php
namespace ApplicationModelEntity;
use DoctrineORMMapping AS ORM;
/**
 * @ORMEntity
 * @ORMInheritanceType("SINGLE_TABLE")
 */
class Capteur
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    private $id;

cli-config.php:

<?php
use DoctrineORMToolsConsoleConsoleRunner;
require_once 'bootstrap.php';
$entityManager =GetEntityManager ();
return ConsoleRunner::createHelperSet ( $entityManager );

bootstrap.php(除了添加mysql枚举之外,我没有做任何特别的事情):

<?php
require_once "vendor/autoload.php";
use DoctrineORMToolsSetup;
use DoctrineORMEntityManager;
function GetEntityManager() {
    $paths = array (
            'module/Application/src' 
    );
    $isDevMode = true;
    // the connection configuration
    $localConfig = include __DIR__ . '/autoload/local.php';
    $dbParams = $localConfig ['doctrine'] ['connection'] ['orm_default'] ['params'];
    $config = Setup::createAnnotationMetadataConfiguration ( $paths, $isDevMode, "data/proxies", null, false );
    $entityManager = EntityManager::create ( $dbParams, $config );
    $platform = $entityManager->getConnection ()->getDatabasePlatform ();
    $platform->registerDoctrineTypeMapping ( 'enum', 'string' );
    return $entityManager;
}

谢谢。我终于找到了一个解决方案:强制Zend自动加载器的行为。但我仍然觉得必须这么做很奇怪。

我在bootstrap.hp:的开头添加了这些行

<?php
require_once "vendor/autoload.php";
//insert
ZendLoaderAutoloaderFactory::factory ( array (
        'ZendLoaderStandardAutoloader' => array (
                ZendLoaderStandardAutoloader::LOAD_NS => array (
                        "Application" => __DIR__ . "/../module/Application/src/Application" 
                ) 
        ) 
) );

相关内容

  • 没有找到相关文章

最新更新