我正在使用Doctrine2构建Zend Framework 2网站。我在Windows上开发并且一切正常但我已将代码上传到Linux环境并且出现了这个错误:
The target-entity LeuerOneYear\Entity\UserLeagueRole cannot be found in 'User\Entity\User#leagueRoles'.
这些是我的实体:
<?php
namespace User\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use LeuerOneYear\Entity\UserLeagueRole;
use Doctrine\Common\Collections\ArrayCollection;
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity
*/
class User
{
/**
* @var integer
*
* @ORM\Column(name="UserId", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="Login", type="string", length=15, nullable=false)
*/
private $login;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=45, nullable=false)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="Email", type="string", length=100, nullable=false)
*/
private $email;
/**
* @var \DateTime
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="CreatedOn", type="datetime", nullable=false)
*/
private $createdon;
/**
*
* @var string
*/
private $appRole;
/**
*
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="LeuerOneYear\Entity\UserLeagueRole", mappedBy="user", cascade={"persist"})
*/
private $leagueRoles;
和:
<?php
namespace LeuerOneYear\Entity;
use Doctrine\ORM\Mapping as ORM;
use User\Entity\User;
/**
* Userleaguerole
*
* @ORM\Table(name="userleaguerole", indexes={@ORM\Index(name="UserRole_League_idx", columns={"LeagueId"}), @ORM\Index(name="UserRole_Role_idx", columns={"RoleId"}), @ORM\Index(name="IDX_5D9987ED631A48FA", columns={"UserId"})})
* @ORM\Entity
*/
class UserLeagueRole
{
// /**
// * @var \User\Entity\User
// *
// * @ORM\Id
// * @ORM\GeneratedValue(strategy="NONE")
// * @ORM\OneToMany(targetEntity="User\Entity\User", mappedBy="leaguerole")
// * })
// */
/**
*
* @var User\Entity\User $user
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\ManyToOne(targetEntity="User\Entity\User", inversedBy="leagueRoles")
* @ORM\JoinColumn(name="UserId", referencedColumnName="UserId")
*/
private $user;
/**
* @var \LeuerOneYear\Entity\League
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\ManyToOne(targetEntity="LeuerOneYear\Entity\League", inversedBy="userRoles")
* @ORM\JoinColumn(name="LeagueId", referencedColumnName="LeagueId")
*
*/
private $league;
/**
* @var \LeuerOneYear\Entity\LeagueRole
*
* @ORM\ManyToOne(targetEntity="LeuerOneYear\Entity\LeagueRole")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="RoleId", referencedColumnName="RoleId")
* })
*/
private $role;
正如您所看到的那样,User和UserLeagueRole之间存在许多关系。
你知道为什么这个映射在Windows上工作但在Linux中失败了吗?
答案 0 :(得分:0)
我真的很傻:
这是我的目录结构:
RootFolder /模块/ LeuerOneYear / SRC / leuerOneYear
然后在我的module.config.php中,我以这种方式配置我的学说驱动程序:
'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'
)
),
),
__NAMESPACE__
是'LeuerOneYear',而不是'leuerOneYear',因此Linux情况确实如此,映射失败。
我刚将module / src / leuerOneyear重命名为module / src / LeuerOneYear