Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query builder Call to a member function createQueryBuilder() on a non-object

I'm trying to use Query Builder in Symfony2.3 and I keep getting the error: FatalErrorException: Error: Call to a member function createQueryBuilder() on a non-object in...line 45

which is the second part of my query,

$query = $tokenobject->createQueryBuilder('t')
        ->select('t.token','t.user', 't.expirationdate')
        ->where('t.user = :username','t.token = :token')
        ->setParameter('username', $Username)
        ->setParameter('token', $Token)
        ->orderBy('t.expirationdate', 'ASC')
        ->setMaxResults(1);

The entire code if it helps:

$confirmationrepository = $this->getDoctrine()
        ->getRepository('TravelTravelBundle:Confirmation')
        ->findByuser($Username);

        $query = $confirmationrepository ->createQueryBuilder('t')
        ->select('t.token','t.user', 't.expirationdate')
        ->where('t.user = :username','t.token = :token')
        ->setParameter('username', $Username)
        ->setParameter('token', $Token)
        ->orderBy('t.expirationdate', 'ASC')
        ->setMaxResults(1);
        $token = $query->getResult();

I know for a fact $confirmationrepository is finding table column'user' properly and that $Username and $Token (being routed into controller) are set and routing properly.

Is there something wrong with my syntax, or is there some other explanation for what is happening?


1 Answers

$confirmationrepository = $this->getDoctrine()
        ->getRepository('TravelTravelBundle:Confirmation')
        ->findByuser($Username);

should be

$confirmationrepository = $this->getDoctrine()
        ->getRepository('TravelTravelBundle:Confirmation');
like image 103
xdazz Avatar answered Feb 14 '26 19:02

xdazz