首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Doctrine存储库"Doctrine\ORM\EntityRepository“必须实现Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface

Doctrine存储库"Doctrine\ORM\EntityRepository“必须实现Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface
EN

Stack Overflow用户
提问于 2016-01-28 12:24:36
回答 1查看 728关注 0票数 2

我收到了错误The Doctrine repository "Doctrine\ORM\EntityRepository" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.

这主要是按照symfony自己的登录、数据库和理论示例来完成的,并进行了一些定制。

Customer.php:`

代码语言:javascript
复制
// src/AppBundle/Entity/Customer.php

namespace AppBundle\Entity;

 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Security\Core\User\UserInterface;
 use Symfony\Component\Security\Core\User\AdvancedUserInterface;

  /**
   * @ORM\Entity(repositoryClass="AppBundle\Entity\CustomerRepository")
   */

 class Customer implements AdvancedUserInterface, \Serializable
 {

 /**
 * @var integer
 */
private $id;

/**
 * @var string
 */
private $customer_firstname;

/**
 * @var string
 */
private $customer_lastname;

/**
 * @var string
 */
private $customer_email;

/**
 * @var string
 */
private $customer_password;

/**
 * @var string
 */
private $customer_salt;

/**
 * @var string
 */
private $customer_notes;

/**
 * @var integer
 */
private $customer_server_id;

/**
 * @var string
 */
private $customer_panel_account;

/**
 * @var integer
 */
private $customer_invoicing_account;

/**
 * @var integer
 */
private $customer_is_active;


/**
 * Set id
 *
 * @param integer $id
 *
 * @return Customer
 */
public function setId($id)
{
    $this->id = $id;

    return $this;
}

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Set customerFirstname
 *
 * @param string $customerFirstname
 *
 * @return Customer
 */
public function setCustomerFirstname($customerFirstname)
{
    $this->customer_firstname = $customerFirstname;

    return $this;
}

/**
 * Get customerFirstname
 *
 * @return string
 */
public function getCustomerFirstname()
{
    return $this->customer_firstname;
}

/**
 * Set customerLastname
 *
 * @param string $customerLastname
 *
 * @return Customer
 */
public function setCustomerLastname($customerLastname)
{
    $this->customer_lastname = $customerLastname;

    return $this;
}

/**
 * Get customerLastname
 *
 * @return string
 */
public function getCustomerLastname()
{
    return $this->customer_lastname;
}

/**
 * Set customerEmail
 *
 * @param string $customerEmail
 *
 * @return Customer
 */
public function setCustomerEmail($customerEmail)
{
    $this->customer_email = $customerEmail;

    return $this;
}

/**
 * Get customerEmail
 *
 * @return string
 */
public function getCustomerEmail()
{
    return $this->customer_email;
}

/**
 * Set customerPassword
 *
 * @param string $customerPassword
 *
 * @return Customer
 */
public function setCustomerPassword($customerPassword)
{
    $this->customer_password = $customerPassword;

    return $this;
}

/**
 * Get customerPassword
 *
 * @return string
 */
public function getCustomerPassword()
{
    return $this->customer_password;
}

/**
 * Set customerSalt
 *
 * @param string $customerSalt
 *
 * @return Customer
 */
public function setCustomerSalt($customerSalt)
{
    $this->customer_salt = $customerSalt;

    return $this;
}

/**
 * Get customerSalt
 *
 * @return string
 */
public function getCustomerSalt()
{
    return $this->customer_salt;
}

/**
 * Set customerNotes
 *
 * @param string $customerNotes
 *
 * @return Customer
 */
public function setCustomerNotes($customerNotes)
{
    $this->customer_notes = $customerNotes;

    return $this;
}

/**
 * Get customerNotes
 *
 * @return string
 */
public function getCustomerNotes()
{
    return $this->customer_notes;
}

/**
 * Set customerServerId
 *
 * @param integer $customerServerId
 *
 * @return Customer
 */
public function setCustomerServerId($customerServerId)
{
    $this->customer_server_id = $customerServerId;

    return $this;
}

/**
 * Get customerServerId
 *
 * @return integer
 */
public function getCustomerServerId()
{
    return $this->customer_server_id;
}

/**
 * Set customerPanelAccount
 *
 * @param string $customerPanelAccount
 *
 * @return Customer
 */
public function setCustomerPanelAccount($customerPanelAccount)
{
    $this->customer_panel_account = $customerPanelAccount;

    return $this;
}

/**
 * Get customerPanelAccount
 *
 * @return string
 */
public function getCustomerPanelAccount()
{
    return $this->customer_panel_account;
}

/**
 * Set customerInvoicingAccount
 *
 * @param integer $customerInvoicingAccount
 *
 * @return Customer
 */
public function setCustomerInvoicingAccount($customerInvoicingAccount)
{
    $this->customer_invoicing_account = $customerInvoicingAccount;

    return $this;
}

/**
 * Get customerInvoicingAccount
 *
 * @return integer
 */
public function getCustomerInvoicingAccount()
{
    return $this->customer_invoicing_account;
}

public function isAccountNonExpired()
{
  return true;
}

public function isAccountNonLocked()
{
  return true;
}

public function isCredentialsNonExpired()
{
  return true;
}

/**
 * Check if customer accoutn is activate
 *
 */

 public function isEnabled()
 {
   return $this->customer_is_active;
 }

/**
 * Set customerIsActive
 *
 * @param integer $customerIsActive
 *
 * @return Customer
 */
public function setCustomerIsActive($customerIsActive)
{
    $this->customer_is_active = $customerIsActive;

    return $this;
}

/**
 * Get customerIsActive
 *
 * @return integer
 */
public function getCustomerIsActive()
{
    return $this->customer_is_active;
}

/** Added these functions because of the security controller */

/**
 * Get username
 *
 * @return string
 */
 public function getUsername()
 {
   return $this->customer_email;
 }

 public function getPassword()
 {
   return $this->customer_password;
 }

 public function getSalt()
 {
   return $this->customer_salt;
 }

 public function getRoles()
 {
   return array('ROLE_USER');
 }

 public function eraseCredentials()
 {

 }

 public function serialize()
 {
    return serialize(array(
      $this->id,
      $this->customer_email,
      $this->customer_password,
      $this->customer_is_active
    ));
 }

 public function unserialize($serialized)
 {
   list (
    $this->id,
    $this->customer_email,
    $this->customer_password,
    $this->customer_is_active
   ) = unserialize($serialized);
 }
}

CustomerRepository.php:

代码语言:javascript
复制
<?php

 //src/AppBundle/Entity/CustomerRepository.php

use Symfony\Bridge\Doctrine\Security\User\UserloadInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Doctrine\ORM\EntityRepository;

class CustomerRepository extends EntityRepository implements   UserLoaderInterface
{

public function loadUserByUsername($email)
  {
  $user = $this->createQueryBuilder('c')
    ->where('c.customer_email = :email')
    ->setParameter('email', $email)
    ->getQuery()
    ->getOneOrNullResult();

    if(null === $user)
    {
      $message = sprintf(
        'Unable to find an active user AppBundle:User object identified by "%s".',
        $email
      );
      throw new UsernameNotFoundException($message);

    }

    return $user;
}
}

从去年开始,我在这里发现了一个类似的问题(堆栈溢出),认为它适用于2.5版*,但它并没有帮助我。我在用symfony3。链接到问题:The Doctrine repository "Doctrine\ORM\EntityRepository" must implement UserProviderInterface in symfony2

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-28 17:23:50

不能混合注释和yaml/xml映射,这意味着将检索默认存储库类而不是自定义类。将存储库类行添加到参考资料/config/主义下的映射文件中。

代码语言:javascript
复制
# customer.orm.yml
AppBundle\Entity\Game:
  type:  entity
  table: customers
  repositoryClass: AppBundle\Entity\CustomerRepository
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35061413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档