刷新时symfony doctrine错误

时间:2016-12-10 13:20:24

标签: php orm doctrine-orm symfony

我有一个带有resetPasswordAction的SecurityController,如下所示:

  /**
   * @Route("/reset-password", name="security.resetPassword")
   */
  public function resetPasswordAction(Request $request) {

    if (!$request->isMethod('POST')) {
      return $this->render('security/reset-password.html.twig');
    }

    $em =$this->getDoctrine()->getManager();

    $email = $request->request->get('_email');
    if (filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) {
      $this->addFlash(
        'danger',
        sprintf('<strong>%s</strong> is not a valid email address', $email)
      );
      return $this->render('security/reset-password.html.twig');
    }
    $userRepository = $this->getDoctrine()->getRepository('AppBundle:User');

    /**
     * @var $user User
     */
    $user = $userRepository->findOneBy(['email' => $email]);

    if (NULL == $user) {
      $this->addFlash('danger', 'No user found...');
      return $this->redirectToRoute('security.login');
    }

    $token = base64_encode(random_bytes(20));

    $user->setConfirmationToken($token);
    $user->setPasswordRequestedAt();
    $em->flush();
    $this->addFlash('success', 'You got mail...');
    return $this->redirectToRoute('security.login');
  }

我的问题是我在$em->flush上收到此错误:

Warning: Illegal offset type in isset or empty

堆栈跟踪显示此错误:

CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: Illegal offset type in isset or empty" at /Users/foobar/Sites/dev/crm/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php line 189 

当我使用注入的EntityManager和UserRepository为此构建服务时,我得到了同样的错误。

我无法弄清楚为什么会出现这种错误。

也许有人建议我如何解决这个问题?

---&GT;更新

我的用户类看起来像(没有方法):

<?php

namespace AppBundle\Entity;


use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @ORM\Table(name="users")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
 * @UniqueEntity(fields="email", message="Email already taken")
 * @UniqueEntity(fields="username", message="Username already taken")
 */
class User implements UserInterface, \Serializable {
  /**
   * @ORM\Column(type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;

  /**
   * @ORM\Column(type="string", length=25, unique=true)
   * @Assert\NotBlank(message="Please provide a username")
   */
  private $username;

  /**
   * @Assert\NotBlank()
   * @Assert\Length(max=4096)
   */
  private $plainPassword;

  /**
   * @ORM\Column(type="string", length=64)
   */
  private $password;

  /**
   * @ORM\Column(type="string", length=60, unique=true)
   * @Assert\NotBlank(message="Please provide a email")
   */
  private $email;

  /**
   * @ORM\Column(type="string", length=255)
   */
  private $roles;

  /**
   * @ORM\Column(type="boolean")
   */
  private $isActive;

  /**
   * @ORM\Column(type="string", length=255, nullable=True)
   */
  private $confirmationToken;

  /**
   * @ORM\Column(type="datetime", nullable=True)
   */
  private $passwordRequestedAt;

0 个答案:

没有答案