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')

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

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳