1

我在 symfony 中定义自定义存储库类以使用一些自定义查询(方法 User::checkUser())时遇到问题。

这是存储库类代码

<?php
namespace TDDumb\FEBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\EntityRepository;
/**
 *
 *  @ORM\Entity(repositoryClass="TDDumb\FEBundle\Entity\UserRepository")
 *  @ORM\Table(name="user")
 *
 */

class User extends EntityRepository{
    public function __construct(){
    }
    /**
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     *
     * @ORM\Column(type="string", length=16)
     */
    protected $userID;
    /**
     *
     * @ORM\Column(type="string", length=16)
     */
    protected $password;


[GETTER AND SETTER...]

    public function checkUser(){
        return $this->getEntityManager()->createQuery("SELECT u FROM TDDumbFEBundle:user u WHERE u.userID = '{$this->userID}' AND u.password = '{$this->password}'")->getResult();
    }
}

这是我的控制器代码:

public function loginAction(Request $request){
        $user = new User();

        $form = $this->createFormBuilder($user)
        ->add('userID', 'text', array('label' => 'UserID'))
        ->add('password', 'password', array('label' => 'Password'))
        ->add('ricorda', 'checkbox', array(
                "required" => false,
                "mapped" => false
        ))
        ->add('login', 'submit')->getForm();

        $form->handleRequest($request);

        if($form->isValid()){
            //$dbUser = $this->getDoctrine()->getRepository('TDDumbFEBundle:User')->findOneByUserID($user->getUserID());
            $em = $this->getDoctrine()->getManager();
            $res = $em->getRepository('TDDumbFEBundle:User')->checkUser();
            Debug::dump($res);
        }
        return $this->render('TDDumbFEBundle:Default:auth.html.twig', array('form' => $form->createView()));
    }

我不明白为什么我总是收到此错误:

FatalErrorException: Error: Class 'TDDumb\FEBundle\Entity\UserRepository' not found in /var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 689

其中指向类文件中的映射定义:

@ORM\Entity(repositoryClass="TDDumb\FEBundle\Entity\UserRepository")

哪个是正确的,我想

4

0 回答 0