[英]Errors Integrating Doctrine Into Zend Framework
When trying to run a simple command $msg = $this->_em->find("Entities\\Message", 1); 尝试运行简单命令$ msg = $ this-> _ em-> find(“ Entities \\ Message”,1); in my IndexController I get the following errors:
在我的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
Here is my doctrine bootstrap code: 这是我的理论引导代码:
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);
}
I am using Doctrine 2.0.4. 我正在使用Doctrine 2.0.4。
I can't think of any other info to provide, but I would be happy to add more information if needed. 我想不出任何其他信息,但是如果需要,我很乐意添加更多信息。
Make sure you have the following class in application/models/Entities/Message.php
确保您在
application/models/Entities/Message.php
具有以下类
namespace Entities;
/**
* @Entity
*/
class Message
{
// ...
Also, I'm not sure about this line 另外,我不确定这条线
// load the doctrine class loader for Symfony library components
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'Doctrine');
Isn't that saying the Symfony
namespace / folder is in the Doctrine
directory? 这不是说
Symfony
名称空间/文件夹在Doctrine
目录中吗?
Edit: My guess would be it should look like this 编辑:我猜应该是这样
$classLoader = new \Doctrine\Common\ClassLoader('Symfony');
I think I see what's missing. 我想我明白了什么。 You aren't telling the annotation driver where to find your entities.
您没有告诉注释驱动程序在哪里可以找到您的实体。
I think this line 我认为这条线
$driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/configs/doctrine/Mapping');
$ driverImpl = $ config-> newDefaultAnnotationDriver(APPLICATION_PATH。'/ configs / doctrine / Mapping');
should be 应该
$driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/models/Entities');
See http://www.doctrine-project.org/docs/orm/2.0/en/reference/configuration.html 参见http://www.doctrine-project.org/docs/orm/2.0/en/reference/configuration.html
I highly recommend you check out the Bisna integration from Guilherme Blanco - https://github.com/guilhermeblanco/ZendFramework1-Doctrine2 我强烈建议您从Guilherme Blanco查看Bisna集成-https: //github.com/guilhermeblanco/ZendFramework1-Doctrine2
I also have a sort of ZF/Doctrine2 app skeleton here that you're welcome to look at - https://github.com/philBrown/ZFDoctrineSkeleton 我在这里也有一种ZF / Doctrine2应用程序框架,欢迎您关注-https: //github.com/philBrown/ZFDoctrineSkeleton
Looks like you're not pushing your Doctrine, Symfony, and Entities class loaders onto the Zend autoloader: 看起来您没有将Doctrine,Symfony和Entities类加载器推到Zend自动加载器上:
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');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.