简体   繁体   中英

Doctrine Query Builder not working with CodeIgniter

I have the following code in a function in one of my controllers:

$qb = $this->doctrine->em->createQueryBuilder();
$query = $qb->select('username, password, level')
    ->from('User', 'u');
        // ->where('user.username = :username')
        // ->setParameter('username', 'userTest');
$users = $query->getResult();

which causes something to fail silently. No error message, the only thing I get from the page is a 500 server error. If I comment out the $users = $query->getResult() line the page loads just fine, so it seems that the query builder is just not working here. I have no idea why though. Do I need to somehow load it in my Doctrine.php library file? I don't think so.

Another odd thing I've discovered is if I try to retrieve entries via the getRepository method it prints out DQL statement to the output of the page, as in that method itself for some reason prints out a DQL statement. I do not take the result of it and print it out.

Any idea what's going on here? My User class is pretty simple. Unfortunately I don't know what's wrong as there's no error being reported. D:

<?php
namespace Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class User {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     */
    private $username;

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

    /**
     * @ORM\Column(type="integer")
     */
    private $level;

    /**
     * @ORM\OneToMany(targetEntity="EmailAddress", mappedBy="user")
     */
    private $emails;
}

?>

You missed a step !

Look the doctrine documentation .

Try : $users = $query->getQuery()->getResult();

And change : $qb->select('u.username, u.password, u.level')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM