doutuo3935 2013-02-14 00:22
浏览 27
已采纳

Doctrine Query Builder不使用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;
}

?>
  • 写回答

1条回答 默认 最新

  • dongye4192 2013-02-14 08:55
    关注

    You missed a step !

    Look the doctrine documentation.

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R