但我在注册实体中添加了@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);
答案 0 :(得分:4)
在Controller中创建new registrationRepository
(实例化)manualy是这样做的错误方法。相反,你必须使用doctrine getRepository
方法:
$em = $this->getDoctrine()->getManager();
$registrationRepo = $em->getRepository('RepairStoreBundle:registration');
$result = $registrationRepo ->auth($name);
阅读the docs。
此外,您应该从存储库类中删除__construct
方法。