我在收集记录中的第5条记录时遇到问题,在运行之后,运行正常: -
$em = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('doctrine');
$arrRoleResources = $em->getRepository("AJFIT\Entities\UserRoleResources")->findAll();
当我经历这个: -
foreach($arrRoleResources as $roleResource) {
self::$_objAcl->allow($roleResource->getRoleFk()->getName(),$roleResource->getResourcesFk()->getModule() . '::' . $roleResource->getResourcesFk()->getController() . '::' . $roleResource->getResourcesFk()->getAction());
}
在第5次迭代中,它将一个相关的记录类从一个实体更改为一个压缩和正确的代理,但是当它到达加载函数时单步执行代理(AJFITEntityUserRoleResourcesProxy): -
private function _load()
{
if (!$this->__isInitialized__ && $this->_entityPersister) {
$this->__isInitialized__ = true;
if ($this->_entityPersister->load($this->_identifier, $this) === null) {
throw new \Doctrine\ORM\EntityNotFoundException();
}
unset($this->_entityPersister, $this->_identifier);
}
}
抛出EntityNotFoundException。
当我在第581行的BasicEntityPersister.php中逐步执行$ this-> _entityPersister-> load()函数时: -
$entities = $hydrator->hydrateAll($stmt, $this->_rsm, $hints);
$ entities返回null,我不确定为什么。
这是我的配置: -
Root
|-----application
|-----library
|-----AJFIT
| |-----Entities (namespaces = AJFIT\Entities)
| | |-----UserResources.php
| | |-----UserRoleResources.php
| | |-----UserRoles.php
| |-----Proxies (namespaces = AJFIT\Proxies) <-auto generated
| |-----AJFITEntitiesUserResources.php
| |-----AJFITEntitiesUserRoleResources.php
| |-----AJFITEntitiesUserRoles.php
|-----Doctrine
|-----Zend
|-----ZendX
我的应用程序配置
[production]
autoloadernamespaces[] = "AJFIT"
autoloadernamespaces[] = "Doctrine"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1
resources.frontController.baseurl = "/"
resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view.encoding = "UTF-8"
resources.view.basePath = APPLICATION_PATH "/views/"
; ------------------------------------------------------------------------------
; Doctrine Database Configuration
; ------------------------------------------------------------------------------
doctrine.conn.host = '127.0.0.1'
doctrine.conn.user = 'ajfit'
doctrine.conn.pass = '*****'
doctrine.conn.driv = 'pdo_mysql'
doctrine.conn.dbname = 'ajfit'
doctrine.path.entities = APPLICATION_PATH "../../library/AJFIT/Entities"
My Bootstrap: -
/**
* Register namespace Default_
* @return Zend_Application_Module_Autoloader
*/
protected function _initAutoload()
{
$autoloader = new \Doctrine\Common\ClassLoader('Zend');
$autoloader->setNamespaceSeparator('_');
$autoloader->register();
return $autoloader;
}
/**
* Initialize Doctrine
* @return Doctrine_Manager
*/
public function _initDoctrine() {
$this->bootstrap('autoload');
// include and register Doctrine's class loader
require_once(APPLICATION_PATH . '/../library/Doctrine/Common/ClassLoader.php');
$classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine',
APPLICATION_PATH . '/../library/Doctrine'
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Symfony',
APPLICATION_PATH . '/../library/Doctrine/Symfony'
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'AJFIT',
APPLICATION_PATH . '/../library/AJFIT/'
);
$classLoader->register();
// create the Doctrine configuration
$config = new \Doctrine\ORM\Configuration();
// setting the cache ( to ArrayCache. Take a look at
// the Doctrine manual for different options ! )
$cache = new \Doctrine\Common\Cache\ArrayCache;
//$cache = new \Doctrine\Common\Cache\ApcCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// choosing the driver for our database schema
// we'll use annotations
$driver = $config->newDefaultAnnotationDriver(
APPLICATION_PATH . '/../library/AJFIT/Entities'
);
//$driver = new Doctrine\ORM\Mapping\Driver\XmlDriver(
// APPLICATION_PATH . '/../library/AJFIT/Mappings/XML');
//$driver = new Doctrine\ORM\Mapping\Driver\YamlDriver(
// APPLICATION_PATH . '/../library/AJFIT/Mappings/YML');
$config->setMetadataDriverImpl($driver);
// set the proxy dir and set some options
$config->setProxyDir(APPLICATION_PATH . '/../library/AJFIT/Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setProxyNamespace('AJFIT\Proxies');
// now create the entity manager and use the connection
// settings we defined in our application.ini
$connectionSettings = $this->getOption('doctrine');
$conn = array(
'driver' => $connectionSettings['conn']['driv'],
'user' => $connectionSettings['conn']['user'],
'password' => $connectionSettings['conn']['pass'],
'dbname' => $connectionSettings['conn']['dbname'],
'host' => $connectionSettings['conn']['host']
);
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
// push the entity manager into our registry for later use
$registry = Zend_Registry::getInstance();
$registry->em = $entityManager;
return $entityManager;
}
请帮助我,因为我已经在这几个星期工作了几个星期,而且我似乎没有随处可见。
感谢您的时间
安德鲁
答案 0 :(得分:0)
它没有直接回答你的问题,但如果我是你,我会使用'Bisna'胶水作为ZF和Doctrine2:https://github.com/ralphschindler/NOLASnowball
要获得一个好的教程视频:http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/
标题可能听起来令人困惑,但视频很好地解释了如何整合ZF和Doctrine2。
这种“粘合剂”对我来说总是很有效,我认为它也可以解决你的问题。
答案 1 :(得分:0)
感谢您的帮助,我已经粘贴了doctrine 2.1.2和zend 1.11.11,没有任何问题,我发现我收到此错误的原因是由于相关实体在数据库中为空而导致正确的错误。
但是我遇到这个奇怪的问题,一个关联实体是一个代理类,它的方法总是返回null。我希望有人可以对这个问题有所了解,因为我会让我疯狂。
我正在调用此代码: -
$arrRoleResources = $em->getRepository("AJFIT\Entity\UserRoleResources")->findAll();
foreach($arrRoleResources as $roleResource) {
$name = $roleResource->getRoleFk()->getName();
}
UserRoleResources实体: -
namespace AJFIT\Entity;
/**
* UserRoleResources
*
* @Table(name="user_role_resources")
* * @Entity(repositoryClass="AJFIT\Repository\UserRoleResources")
*/
class UserRoleResources
{
/**
* @var UserRoles
*
* @ManyToOne(targetEntity="UserRoles")
* @JoinColumn(name="role_fk", referencedColumnName="pk")
*
*/
private $roleFk;
/**
* Get roleFk
*
* @return UserRoles $roleFk
*/
public function getRoleFk()
{
return $this->roleFk;
}
}
UserRole实体: -
namespace AJFIT\Entity;
/**
* UserRoles
*
* @Table(name="user_roles")
* * @Entity(repositoryClass="AJFIT\Repository\UserRoles")
*/
class UserRoles
{
/**
* @var string $name
*
* @Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var integer $pk
*
* @Column(name="pk", type="integer")
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $pk;
/**
* Get name
*
* @return string $name
*/
public function getName()
{
return $this->name;
}
}
我已经按照zf-boilerplate预编译的示例,如果需要,我可以发布我的配置。谢谢
: - )