0

但是我已经@ORM\Entity(repositoryClass="Repair\StoreBundle\Entity\registrationRepository")在注册实体中添加了,但我仍然在附近出现错误createQuery()

我的registrationRepository.php是

use Doctrine\ORM\EntityRepository;

/**
 * registrationRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */

class registrationRepository extends EntityRepository
{

    function __construct() {
    }

    public function auth($name,$password)
    {
        $em = $this->getEntityManager();

        $result = $em->createQuery("SELECT r.username,r.password FROM RepairStoreBundle:registration r where r.username='".$name."' and r.password='".$password."'")->getResult();
        return  $query;

    }   
}

我的控制器以这种方式调用

$test = new registrationRepository();
$result = $test->auth($name);
4

1 回答 1

4

new registrationRepository在 Controller 中手动创建(实例化)是错误的做法。相反,您必须使用学说getRepository方法:

$em = $this->getDoctrine()->getManager();
$registrationRepo = $em->getRepository('RepairStoreBundle:registration');
$result = $registrationRepo ->auth($name);

阅读文档

更新

您还应该__construct从存储库类中删除方法。

于 2013-05-14T10:15:22.750 回答