Php 将条令整合到Zend框架中的错误

Php 将条令整合到Zend框架中的错误,php,doctrine,doctrine-orm,Php,Doctrine,Doctrine Orm,尝试运行简单命令$msg=$this->\u em->find(“Entities\Message”,1);在我的IndexController中,我得到以下错误: ( ! ) Warning: class_parents() [function.class-parents]: Class Entities\Message does not exist and could not be loaded in C:\wamp\www\KosherOven\library\Doctrine\ORM\M

尝试运行简单命令$msg=$this->\u em->find(“Entities\Message”,1);在我的IndexController中,我得到以下错误:

( ! ) Warning: class_parents() [function.class-parents]: Class Entities\Message does not exist and could not be loaded in C:\wamp\www\KosherOven\library\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
Call Stack
#   Time    Memory  Function    Location
1   0.0006  372272  {main}( )   ..\index.php:0
2   0.0918  5254808 Zend_Application->run( )    ..\index.php:27
3   0.0918  5254808 Zend_Application_Bootstrap_Bootstrap->run( )    ..\Application.php:366
4   0.0919  5254864 Zend_Controller_Front->dispatch( )  ..\Bootstrap.php:97
5   0.1088  6406328 Zend_Controller_Dispatcher_Standard->dispatch( )    ..\Front.php:954
6   0.1218  6758576 Zend_Controller_Action->dispatch( ) ..\Standard.php:295
7   0.1219  6761896 IndexController->indexAction( ) ..\Action.php:513
8   0.1219  6761992 Doctrine\ORM\EntityManager->find( ) ..\IndexController.php:16
9   0.1225  6764176 Doctrine\ORM\EntityManager->getRepository( )    ..\EntityManager.php:344
10  0.1225  6764240 Doctrine\ORM\EntityManager->getClassMetadata( ) ..\EntityManager.php:567
11  0.1225  6764240 Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor( )    ..\EntityManager.php:251
12  0.1226  6764272 Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata( )  ..\ClassMetadataFactory.php:169
13  0.1226  6764456 Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses( )  ..\ClassMetadataFactory.php:245
14  0.1226  6764608 class_parents ( )   ..\ClassMetadataFactory.php:222

( ! ) Warning: array_reverse() expects parameter 1 to be array, boolean given in C:\wamp\www\KosherOven\library\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
Call Stack
#   Time    Memory  Function    Location
1   0.0006  372272  {main}( )   ..\index.php:0
2   0.0918  5254808 Zend_Application->run( )    ..\index.php:27
3   0.0918  5254808 Zend_Application_Bootstrap_Bootstrap->run( )    ..\Application.php:366
4   0.0919  5254864 Zend_Controller_Front->dispatch( )  ..\Bootstrap.php:97
5   0.1088  6406328 Zend_Controller_Dispatcher_Standard->dispatch( )    ..\Front.php:954
6   0.1218  6758576 Zend_Controller_Action->dispatch( ) ..\Standard.php:295
7   0.1219  6761896 IndexController->indexAction( ) ..\Action.php:513
8   0.1219  6761992 Doctrine\ORM\EntityManager->find( ) ..\IndexController.php:16
9   0.1225  6764176 Doctrine\ORM\EntityManager->getRepository( )    ..\EntityManager.php:344
10  0.1225  6764240 Doctrine\ORM\EntityManager->getClassMetadata( ) ..\EntityManager.php:567
11  0.1225  6764240 Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor( )    ..\EntityManager.php:251
12  0.1226  6764272 Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata( )  ..\ClassMetadataFactory.php:169
13  0.1226  6764456 Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses( )  ..\ClassMetadataFactory.php:245
14  0.1247  6774560 array_reverse ( )   ..\ClassMetadataFactory.php:222

( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp\www\KosherOven\library\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
Call Stack
#   Time    Memory  Function    Location
1   0.0006  372272  {main}( )   ..\index.php:0
2   0.0918  5254808 Zend_Application->run( )    ..\index.php:27
3   0.0918  5254808 Zend_Application_Bootstrap_Bootstrap->run( )    ..\Application.php:366
4   0.0919  5254864 Zend_Controller_Front->dispatch( )  ..\Bootstrap.php:97
5   0.1088  6406328 Zend_Controller_Dispatcher_Standard->dispatch( )    ..\Front.php:954
6   0.1218  6758576 Zend_Controller_Action->dispatch( ) ..\Standard.php:295
7   0.1219  6761896 IndexController->indexAction( ) ..\Action.php:513
8   0.1219  6761992 Doctrine\ORM\EntityManager->find( ) ..\IndexController.php:16
9   0.1225  6764176 Doctrine\ORM\EntityManager->getRepository( )    ..\EntityManager.php:344
10  0.1225  6764240 Doctrine\ORM\EntityManager->getClassMetadata( ) ..\EntityManager.php:567
11  0.1225  6764240 Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor( )    ..\EntityManager.php:251
12  0.1226  6764272 Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata( )  ..\ClassMetadataFactory.php:169
13  0.1226  6764456 Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses( )  ..\ClassMetadataFactory.php:245

( ! ) Fatal error: Cannot redeclare class Message in C:\wamp\www\KosherOven\application\models\Entities\Message.php on line 9
Call Stack
#   Time    Memory  Function    Location
1   0.0006  372272  {main}( )   ..\index.php:0
2   0.0918  5254808 Zend_Application->run( )    ..\index.php:27
3   0.0918  5254808 Zend_Application_Bootstrap_Bootstrap->run( )    ..\Application.php:366
4   0.0919  5254864 Zend_Controller_Front->dispatch( )  ..\Bootstrap.php:97
5   0.1088  6406328 Zend_Controller_Dispatcher_Standard->dispatch( )    ..\Front.php:954
6   0.1218  6758576 Zend_Controller_Action->dispatch( ) ..\Standard.php:295
7   0.1219  6761896 IndexController->indexAction( ) ..\Action.php:513
8   0.1219  6761992 Doctrine\ORM\EntityManager->find( ) ..\IndexController.php:16
9   0.1225  6764176 Doctrine\ORM\EntityManager->getRepository( )    ..\EntityManager.php:344
10  0.1225  6764240 Doctrine\ORM\EntityManager->getClassMetadata( ) ..\EntityManager.php:567
11  0.1225  6764240 Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor( )    ..\EntityManager.php:251
12  0.1226  6764272 Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata( )  ..\ClassMetadataFactory.php:169
13  0.1257  6774344 Doctrine\ORM\Mapping\ClassMetadataFactory->newClassMetadataInstance( )  ..\ClassMetadataFactory.php:260
14  0.1301  7172352 Doctrine\ORM\Mapping\ClassMetadata->__construct( )  ..\ClassMetadataFactory.php:351
15  0.1301  7172592 ReflectionClass->__construct( ) ..\ClassMetadata.php:67
16  0.1302  7172896 Doctrine\Common\ClassLoader->loadClass( )   ..\ClassLoader.php:0
17  0.1305  7182920 require( 'C:\wamp\www\KosherOven\application\models\Entities\Message.php' ) ..\ClassLoader.php:148
这是我的条令引导代码:

protected function _initDoctrine()
{
    /* Autoload classes */
    require_once 'Doctrine/Common/ClassLoader.php';
    $classLoader = new Doctrine\Common\ClassLoader('Doctrine');
    $classLoader->register();
    // load the doctrine class loader for Symfony library components
    $classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
    $classLoader->register();
    $classLoader = new \Doctrine\Common\ClassLoader('Entities', APPLICATION_PATH . '/models');
    $classLoader->register();

    /* Choose cache */

    if (APPLICATION_ENV == "development") {
        $cache = new \Doctrine\Common\Cache\ArrayCache;
    } else {
        //$cache = new \Doctrine\Common\Cache\ApcCache;
        $cache = new \Doctrine\Common\Cache\ArrayCache;
    }

    $config = new \Doctrine\ORM\Configuration;
    $config->setMetadataCacheImpl($cache);

    $driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/configs/doctrine/Mapping');
    $config->setMetadataDriverImpl($driverImpl);
    $config->setQueryCacheImpl($cache);
    $config->setProxyDir(APPLICATION_PATH . '/Proxies');
    $config->setProxyNamespace('Proxies');

    if (APPLICATION_ENV == "development") {
        $config->setAutoGenerateProxyClasses(true);
    } else {
        $config->setAutoGenerateProxyClasses(false);
    }

    $configObj = $this->_initConfig();

    $connectionOptions = array(
        'driver'   => $configObj->database->adapter,
        'dbname'   => $configObj->database->params->dbname,
        'host'     => $configObj->database->params->host,
        'user'     => $configObj->database->params->username,
        'password' => $configObj->database->params->password
    );
    $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

    Zend_Registry::set('em', $em);
}
我使用的是教义2.0.4


我想不出任何其他信息可以提供,但如果需要,我很乐意添加更多信息。

确保在
应用程序/模型/实体/消息.php中有以下类

namespace Entities;

/**
 * @Entity
 */
class Message
{
    // ...

还有,我不确定这条线

// load the doctrine class loader for Symfony library components
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
这不是说
Symfony
名称空间/文件夹在
doctor
目录中吗

编辑:我猜应该是这样的

$classLoader = new \Doctrine\Common\ClassLoader('Symfony');

使现代化 我想我知道少了什么。您没有告诉注释驱动程序在何处查找实体

我想这条线

// load the doctrine class loader for Symfony library components
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
$driverImpl=$config->newDefaultAnnotationDriver(应用程序路径'/configs/doctor/Mapping')

应该是

$driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/models/Entities');

我强烈建议您查看Guillerme Blanco的Bisna集成-


我这里还有一种ZF/Doctrine2应用程序框架,欢迎您查看-

看起来您没有将您的条令、Symfony和实体类加载程序推到Zend autoloader上:

require_once 'Doctrine/Common/ClassLoader.php';
$autoloader = \Zend_Loader_Autoloader::getInstance();

$symfonyAutoloader = new \Doctrine\Common\ClassLoader('Symfony');
$autoloader->pushAutoloader(array($symfonyAutoloader, 'loadClass'), 'Symfony');

$doctrineAutoloader = new \Doctrine\Common\ClassLoader('Doctrine');
$autoloader->pushAutoloader(array($doctrineAutoloader, 'loadClass'), 'Doctrine');

$entityAutoloader = new \Doctrine\Common\ClassLoader('Entities', APPLICATION_PATH . '/models');
$autoloader->pushAutoloader(array($entityAutoloader, 'loadClass'), 'Entities');

你的意思是“application/models/Entities/Message.php”应该包含由条令生成的代码?如果是的话,那就是。我认为cli工具中使用的Symfony组件需要做第二件事。@moteutsch否,生成的代码(代理)进入
application/proxy
,您不必担心它们。在使用注释驱动程序时,您需要为实体创建实际的类。如果您希望实体直接位于
models/
文件夹中,则必须使用Zend的资源自动加载程序。@Cobby不,它们没有。他们已经设置了条令类加载器,以便在
应用程序/模型/实体
中查找
实体
名称空间的类,而他正在注册这些类。PHP可以处理多个自动加载器。