我的开发中出现了下一个错误:
[Doctrine\ORM\Mapping\MappingException]
The target-entity Game\Entity\UserEntity cannot be found in
'Game\Entity\ChallengeRosterEntity#user'.
我有两个模块:
在这些模块中,我定义了几个实体,其中一个实体与属于其他模块的其他实体相关联。
\游戏\实体\ ChallengeRosterEntity.php
<?php
namespace Game\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use User\Entity;
/** @ORM\Entity
* @ORM\Table(name="challenge_roster")
* @ORM\Entity(repositoryClass="Game\Repository\ChallengeRosterRepository")
*/
class ChallengeRosterEntity{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="ChallengeEntity", inversedBy="challengeRoster")
*
**/
protected $challenge;
/**
* @ORM\ManyToOne(targetEntity="UserEntity", inversedBy="userInRosters")
*
**/
protected $user;
/**
* @ORM\Column(type="integer", nullable = true)
*/
protected $points;
/**
* Fecha y hora de creación del roster del desafío por parte del usuario
*
* @ORM\Column(type="datetime", nullable = false)
*/
protected $date;
/**
* @ORM\ManyToMany(targetEntity="BasketballPlayerStatsEntity")
* @ORM\JoinTable(name="players_roster",
* joinColumns={@ORM\JoinColumn(name="challenge_roster_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="basketball_player_stats_id", referencedColumnName="id")}
* )
**/
protected $basketballPlayers;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set points
*
* @param integer $points
* @return ChallengeRosterEntity
*/
public function setPoints($points)
{
$this->points = $points;
return $this;
}
/**
* Get points
*
* @return integer
*/
public function getPoints()
{
return $this->points;
}
/**
* Set date
*
* @param \DateTime $date
* @return ChallengeRosterEntity
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set challenge
*
* @param \Game\Entity\ChallengeEntity $challenge
* @return ChallengeRosterEntity
*/
public function setChallenge(\Game\Entity\ChallengeEntity $challenge = null)
{
$this->challenge = $challenge;
return $this;
}
/**
* Get challenge
*
* @return \Game\Entity\ChallengeEntity
*/
public function getChallenge()
{
return $this->challenge;
}
/**
* Set user
*
* @param \Game\Entity\UserEntity $user
* @return ChallengeRosterEntity
*/
public function setUser(\Game\Entity\UserEntity $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \Game\Entity\UserEntity
*/
public function getUser()
{
return $this->user;
}
/**
* Constructor
*/
public function __construct()
{
$this->basketballPlayers = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add basketballPlayers
*
* @param \Game\Entity\BasketballPlayerStatsEntity $basketballPlayers
* @return ChallengeRosterEntity
*/
public function addBasketballPlayer(\Game\Entity\BasketballPlayerStatsEntity $basketballPlayers)
{
$this->basketballPlayers[] = $basketballPlayers;
return $this;
}
/**
* Remove basketballPlayers
*
* @param \Game\Entity\BasketballPlayerStatsEntity $basketballPlayers
*/
public function removeBasketballPlayer(\Game\Entity\BasketballPlayerStatsEntity $basketballPlayers)
{
$this->basketballPlayers->removeElement($basketballPlayers);
}
/**
* Get basketballPlayers
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getBasketballPlayers()
{
return $this->basketballPlayers;
}
}
\用户\实体\ UserEntity.php
<?php
namespace User\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Game\Entity;
/** @ORM\Entity
* @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="User\Repository\UserRepository")
*/
class UserEntity{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", length = 20, nullable = false)
*/
protected $nick;
/**
* @ORM\Column(type="string", length = 100, nullable = false)
*/
protected $email;
/**
* @ORM\Column(type="string", length = 100, nullable = true)
*/
protected $thumb;
/**
* @ORM\Column(type="integer", nullable = false)
*/
protected $totalRetodones;
/**
* @ORM\Column(type="integer", nullable = false)
*/
protected $challengeWon;
/**
* @ORM\Column(type="integer", nullable = false)
*/
protected $points;
/**
* @ORM\Column(type="integer", nullable = false)
*/
protected $spentRetodones;
/**
* @ORM\Column(type="string", length = 100, nullable = true)
*/
protected $twitterAccount;
/**
* @ORM\Column(type="string", length = 100, nullable = true)
*/
protected $facebookAccount;
/**
* @ORM\OneToMany(targetEntity="StatusEntity", mappedBy="users")
**/
protected $status;
/**
* @ORM\OneToMany(targetEntity="UserEntity", mappedBy="refered")
**/
protected $referedBy;
/**
* @ORM\ManyToOne(targetEntity="UserEntity", inversedBy="referedBy")
* @ORM\JoinColumn(name="refered_id", referencedColumnName="id")
**/
protected $refered;
/**
* @ORM\ManyToMany(targetEntity="UserEntity", mappedBy="myFriends")
**/
protected $friendsWithMe;
/**
* @ORM\ManyToMany(targetEntity="UserEntity", inversedBy="friendsWithMe")
* @ORM\JoinTable(name="user_friends",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="friend_user_id", referencedColumnName="id")}
* )
**/
protected $myFriends;
/**
* @ORM\ManyToOne(targetEntity="ChallengeEntity", inversedBy="userChallenger")
*
**/
//protected $usersChallenger;
/**
* @ORM\ManyToOne(targetEntity="ChallengeEntity", inversedBy="userChallenged")
*
**/
//protected $usersChallenged;
/**
* @ORM\ManyToOne(targetEntity="ChallengeRosterEntity", inversedBy="user")
*
**/
protected $userInRosters;
/**
* Constructor
*/
public function __construct()
{
$this->status = new \Doctrine\Common\Collections\ArrayCollection();
$this->referedBy = new \Doctrine\Common\Collections\ArrayCollection();
$this->friendsWithMe = new \Doctrine\Common\Collections\ArrayCollection();
$this->myFriends = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nick
*
* @param string $nick
* @return UserEntity
*/
public function setNick($nick)
{
$this->nick = $nick;
return $this;
}
/**
* Get nick
*
* @return string
*/
public function getNick()
{
return $this->nick;
}
/**
* Set email
*
* @param string $email
* @return UserEntity
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set thumb
*
* @param string $thumb
* @return UserEntity
*/
public function setThumb($thumb)
{
$this->thumb = $thumb;
return $this;
}
/**
* Get thumb
*
* @return string
*/
public function getThumb()
{
return $this->thumb;
}
/**
* Set totalRetodones
*
* @param integer $totalRetodones
* @return UserEntity
*/
public function setTotalRetodones($totalRetodones)
{
$this->totalRetodones = $totalRetodones;
return $this;
}
/**
* Get totalRetodones
*
* @return integer
*/
public function getTotalRetodones()
{
return $this->totalRetodones;
}
/**
* Set challengeWon
*
* @param integer $challengeWon
* @return UserEntity
*/
public function setChallengeWon($challengeWon)
{
$this->challengeWon = $challengeWon;
return $this;
}
/**
* Get challengeWon
*
* @return integer
*/
public function getChallengeWon()
{
return $this->challengeWon;
}
/**
* Set points
*
* @param integer $points
* @return UserEntity
*/
public function setPoints($points)
{
$this->points = $points;
return $this;
}
/**
* Get points
*
* @return integer
*/
public function getPoints()
{
return $this->points;
}
/**
* Set spentRetodones
*
* @param integer $spentRetodones
* @return UserEntity
*/
public function setSpentRetodones($spentRetodones)
{
$this->spentRetodones = $spentRetodones;
return $this;
}
/**
* Get spentRetodones
*
* @return integer
*/
public function getSpentRetodones()
{
return $this->spentRetodones;
}
/**
* Set twitterAccount
*
* @param string $twitterAccount
* @return UserEntity
*/
public function setTwitterAccount($twitterAccount)
{
$this->twitterAccount = $twitterAccount;
return $this;
}
/**
* Get twitterAccount
*
* @return string
*/
public function getTwitterAccount()
{
return $this->twitterAccount;
}
/**
* Set facebookAccount
*
* @param string $facebookAccount
* @return UserEntity
*/
public function setFacebookAccount($facebookAccount)
{
$this->facebookAccount = $facebookAccount;
return $this;
}
/**
* Get facebookAccount
*
* @return string
*/
public function getFacebookAccount()
{
return $this->facebookAccount;
}
/**
* Add status
*
* @param \User\Entity\StatusEntity $status
* @return UserEntity
*/
public function addStatus(\User\Entity\StatusEntity $status)
{
$this->status[] = $status;
return $this;
}
/**
* Remove status
*
* @param \User\Entity\StatusEntity $status
*/
public function removeStatus(\User\Entity\StatusEntity $status)
{
$this->status->removeElement($status);
}
/**
* Get status
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getStatus()
{
return $this->status;
}
/**
* Add referedBy
*
* @param \User\Entity\UserEntity $referedBy
* @return UserEntity
*/
public function addReferedBy(\User\Entity\UserEntity $referedBy)
{
$this->referedBy[] = $referedBy;
return $this;
}
/**
* Remove referedBy
*
* @param \User\Entity\UserEntity $referedBy
*/
public function removeReferedBy(\User\Entity\UserEntity $referedBy)
{
$this->referedBy->removeElement($referedBy);
}
/**
* Get referedBy
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getReferedBy()
{
return $this->referedBy;
}
/**
* Set refered
*
* @param \User\Entity\UserEntity $refered
* @return UserEntity
*/
public function setRefered(\User\Entity\UserEntity $refered = null)
{
$this->refered = $refered;
return $this;
}
/**
* Get refered
*
* @return \User\Entity\UserEntity
*/
public function getRefered()
{
return $this->refered;
}
/**
* Add friendsWithMe
*
* @param \User\Entity\UserEntity $friendsWithMe
* @return UserEntity
*/
public function addFriendsWithMe(\User\Entity\UserEntity $friendsWithMe)
{
$this->friendsWithMe[] = $friendsWithMe;
return $this;
}
/**
* Remove friendsWithMe
*
* @param \User\Entity\UserEntity $friendsWithMe
*/
public function removeFriendsWithMe(\User\Entity\UserEntity $friendsWithMe)
{
$this->friendsWithMe->removeElement($friendsWithMe);
}
/**
* Get friendsWithMe
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFriendsWithMe()
{
return $this->friendsWithMe;
}
/**
* Add myFriends
*
* @param \User\Entity\UserEntity $myFriends
* @return UserEntity
*/
public function addMyFriend(\User\Entity\UserEntity $myFriends)
{
$this->myFriends[] = $myFriends;
return $this;
}
/**
* Remove myFriends
*
* @param \User\Entity\UserEntity $myFriends
*/
public function removeMyFriend(\User\Entity\UserEntity $myFriends)
{
$this->myFriends->removeElement($myFriends);
}
/**
* Get myFriends
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getMyFriends()
{
return $this->myFriends;
}
/**
* Set userInRosters
*
* @param \User\Entity\ChallengeRosterEntity $userInRosters
* @return UserEntity
*/
public function setUserInRosters(\User\Entity\ChallengeRosterEntity $userInRosters = null)
{
$this->userInRosters = $userInRosters;
return $this;
}
/**
* Get userInRosters
*
* @return \User\Entity\ChallengeRosterEntity
*/
public function getUserInRosters()
{
return $this->userInRosters;
}
}
Doctrine 2在每个文件中都有下一个配置。
\游戏\配置\ module.config.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Game;
return array(
'router' => array(
'routes' => array(
/* 'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
), */
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/juego',
'defaults' => array(
'__NAMESPACE__' => 'Game\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Game\Controller\Index' => 'Game\Controller\IndexController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'game/index/index' => __DIR__ . '/../view/game/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Doctrine config
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
\用户\配置\ module.config.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace User;
return array(
'router' => array(
'routes' => array(
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/user',
'defaults' => array(
'__NAMESPACE__' => 'User\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'User\Controller\Index' => 'User\Controller\IndexController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'user/index/index' => __DIR__ . '/../view/user/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Doctrine config
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
我做错了什么?