Symfony2 类 UserInterface 不存在

标签 symfony user-interface

我正在使用 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 通过以下方式与 CustomerUser 实体建立 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.phpCustomer.php 之间看到的唯一可见差异(其中 showAction 在没有 UserInterface 的情况下工作)。

有人可以帮我调试这个行为吗?仅因为 Symfony 需要(出于未知原因)而拥有一个空的 UserInterface 类似乎确实没有用。

最佳答案

我猜你没有导入 UserInterface的命名空间到您的用户类中(我猜它是一个 User 类,因为您没有提到它):

use Symfony\Component\Security\Core\User\UserInterface;

class User implements UserInterface
{
}

继续阅读PHP namespaces in the official docs .

关于Symfony2 类 UserInterface 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13878029/

相关文章:

C 程序,用户输入到单个数组中

mysql - 从现有数据库生成具有点类型属性的实体

php - 对于 Symfony2 功能测试,验证数据库内容的最佳实践是什么?

java - 调整框架大小时矩形组件消失

java - 带线程的对话框消息

iphone - 退出我的 iPhone 应用程序的按钮是否会违反 Apple 的指导方针?

php - 允许用户在 TWIG 中添加任何代码是一个安全漏洞吗?

php - Symfony2 实体字段类型当前选择

php - 限制用户以 Symfony2 表单提交后检查的单选按钮数量

c# - 如何为 WinForms 控件(即面板)设置 GridLayout