Zend2 框架 - Doctrine ORM 给出映射异常



我正在尝试将Doctrine 2 ORM用于我的一个Zend2应用程序。我在作曲家的帮助下使用 Doctrine 模块在应用程序中进行了设置。

我能够将数据保存到数据库中,但是当我在对象管理器上进行 find() 调用时,它会给我一个映射异常,并显示以下消息。

DoctrineCommonPersistenceMappingMappingException
File:
/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:96
Message:
Class 'User' does not exist

以下是在应用程序模块配置文件下添加的 Doctrine 设置

'driver' => array(
                'application_entities' => array(
                        'class' =>'DoctrineORMMappingDriverAnnotationDriver',
                        'cache' => 'array',
                        'paths' => array(__DIR__ . '/../src/Application/Entity')
                ),
                'orm_default' => array(
                        'drivers' => array(
                                'ApplicationEntity' => 'application_entities'
                        )
                )
        )
),

这是在应用程序\src\实体文件夹下创建的用户实体

<?php
namespace ApplicationEntity;
use DoctrineORMMapping as ORM;
/**
 *  @ORMEntity
 */
class User {
/**
 * @ORMId
 * @ORMColumn(type="integer")
 * @ORMGeneratedValue(strategy="NONE")
 * @var int
 */
protected $user_id;
/**
 * @ORMColumn(type="integer")
 * @var int
 */
protected $network_id;
/**
 * @ORMColumn(type="string", length=64)
 * @var string
 */
protected $network_name;
/**
 * @ORMColumn(type="string", length=64)
 * @var string
 */
protected $job_title;
/**
 * @ORMColumn(type="string", length=64)
 * @var string
 */
protected $location;
/**
 * @ORMColumn(type="string", length=64)
 * @var string
 */
protected $first_name;
/**
 * @ORMColumn(type="string", length=64)
 * @var string
 */
protected $last_name;
/**
 * @ORMColumn(type="string", length=255)
 * @var string
 */
protected $url;
/**
 * @ORMColumn(type="string", length=255)
 * @var string
 */
protected $img_url;
/**
 * @ORMColumn(type="string", length=255)
 * @var string
 */
protected $department;
/**
 * @ORMColumn(type="string", length=255)
 * @var string
 */
protected $email_address;
/**
 * @ORMColumn(type="boolean")
 * @var string
 */
protected $verified;
/**
 * @return the int
 */
public function getUserId() {
    return $this->user_id;
}
/**
 * @param int $user_id
 */
public function setUserId($user_id) {
    $this->user_id = $user_id;
    return $this;
}
/**
 * @return the int
 */
public function getNetworkId() {
    return $this->network_id;
}
/**
 * @param int $network_id
 */
public function setNetworkId($network_id) {
    $this->network_id = $network_id;
    return $this;
}
/**
 * @return the string
 */
public function getNetworkName() {
    return $this->network_name;
}
/**
 * @param string $network_name
 */
public function setNetworkName($network_name) {
    $this->network_name = $network_name;
    return $this;
}
/**
 * @return the string
 */
public function getJobTitle() {
    return $this->job_title;
}
/**
 * @param string $job_title
 */
public function setJobTitle($job_title) {
    $this->job_title = $job_title;
    return $this;
}
/**
 * @return the string
 */
public function getLocation() {
    return $this->location;
}
/**
 * @param string $location
 */
public function setLocation($location) {
    $this->location = $location;
    return $this;
}
/**
 * @return the string
 */
public function getFirstName() {
    return $this->first_name;
}
/**
 * @param string $first_name
 */
public function setFirstName($first_name) {
    $this->first_name = $first_name;
    return $this;
}
/**
 * @return the string
 */
public function getLastName() {
    return $this->last_name;
}
/**
 * @param string $last_name
 */
public function setLastName($last_name) {
    $this->last_name = $last_name;
    return $this;
}
/**
 * @return the string
 */
public function getUrl() {
    return $this->url;
}
/**
 * @param string $url
 */
public function setUrl($url) {
    $this->url = $url;
    return $this;
}
/**
 * @return the string
 */
public function getImgUrl() {
    return $this->img_url;
}
/**
 * @param string $img_url
 */
public function setImgUrl($img_url) {
    $this->img_url = $img_url;
    return $this;
}
/**
 * @return the string
 */
public function getDepartment() {
    return $this->department;
}
/**
 * @param string $department
 */
public function setDepartment($department) {
    $this->department = $department;
    return $this;
}
/**
 * @return the string
 */
public function getEmailAddress() {
    return $this->email_address;
}
/**
 * @param string $email_address
 */
public function setEmailAddress($email_address) {
    $this->email_address = $email_address;
    return $this;
}
/**
 * @return the boolean
 */
public function getVerified() {
    return $this->verified;
}
/**
 * @param boolean $verified
 */
public function setVerified($verfied) {
    $this->verified = $verfied;
    return $this;
}

}

现在,当我从应用程序模块的索引控制器对上述实体进行持久操作时,它工作正常。但是当我在同一个索引控制器中使用相同的对象映射器执行查找操作时,它会给出映射异常。

以下是我的做法:

$objectManager = $this->getServiceLocator()->get('DoctrineORMEntityManager');
$objectManager->persist($user);
$objectManager->flush();
$user = $objectManager->find('User', $uniqueID);

谁能帮我解决这个问题??

问候。

您的实体不叫User而是ApplicationEntityUser。所以替换这一行:

$user = $objectManager->find('User', $uniqueID);

有了这个:

$user = $objectManager->find('ApplicationEntityUser', $uniqueID);

相关内容

  • 没有找到相关文章

最新更新