我正在使用 Symfony 2.1 制作一个客户案例管理系统,我偶然发现了这个我无法解决的奇怪问题。由于某种原因,当我使用 CustomerCaseController
执行 showAction 时,出现以下错误:
"Class HSW\AshaBundle\Entity\UserInterface does not exist"
500 Internal Server Error
我不知道应用程序的哪一部分需要该接口(interface)。 如果我创建一个空的UserInterface.php
类,问题就会消失并且一切正常。为什么 showAction
需要 UserInterface
?
我已经缩小了问题范围,以某种方式与 showController 中的这段代码相关:
$customercase = $this->getDoctrine() ->getRepository('HSWAshaBundle:CustomerCase') ->find($id);
我有以下实体:
用户
(用于登录和提交案例)客户
(针对客户)CustomerCase
(用于案例)。
CustomerCase
通过以下方式与 Customer
和 User
实体建立 ManyToOne 关系:
//src/HSW/AshaBundle/Entity/CustomerCase.php 命名空间 HSW\AshaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
/**
* CustomerCase
*
* @ORM\Table(name="hsw_customerCase")
* @ORM\Entity
* @Gedmo\Loggable
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class CustomerCase
{
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="customerCases")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=false)
*/
protected $customer;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="createdCustomerCases")
* @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=false)
*/
protected $creator;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="holdingCustomerCases")
* @ORM\JoinColumn(name="holder_id", referencedColumnName="id", nullable=false)
*/
protected $holder;
.....etc....
//src/HSW/AshaBundle/Entity/CustomerCase.php 命名空间 HSW\AshaBundle\Entity;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\Common\Collections\ArrayCollection;
/**
* HSW\AshaBundle\Entity\User
*
* @ORM\Table(name="hsw_users")
* @ORM\Entity(repositoryClass="HSW\AshaBundle\Entity\UserRepository")
*/
class User implements AdvancedUserInterface
{
.....etc....
与 User 实体的关系是否会以某种方式影响此问题?这是我在 CustomerCase.php
和 Customer.php
之间看到的唯一可见差异(其中 showAction
在没有 UserInterface
的情况下工作)。
有人可以帮我调试这个行为吗?仅因为 Symfony 需要(出于未知原因)而拥有一个空的 UserInterface 类似乎确实没有用。
最佳答案
我猜你没有导入 UserInterface的命名空间到您的用户类中(我猜它是一个 User 类,因为您没有提到它):
use Symfony\Component\Security\Core\User\UserInterface;
class User implements UserInterface
{
}
关于Symfony2 类 UserInterface 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13878029/