如何在代码点火器中使用条令查询生成器


how to using doctrine query builder in codeigniter?

我有一个问题:我正在使用条令2和代码点火器2。我想知道条令查询生成器是如何工作的?我想在条令查询生成器上使用select查询,但我做不到。我也读过条令文件并尝试过,但没有成功。

在尝试了这个之后,我得到了这个错误消息:

致命错误:未捕获异常"Doctrine''ORM''Query''QueryException",消息为"SELECT u.username,u.password,u.email FROM Entity''Userss u,Userss u ORDER BY u.username ASC'in C:''xamplep''htdocs''hotell''application''librares''Doctrine''ORM''QueryException.php:39堆栈跟踪:#0 C:''xamplep ''htdocs''hotell''aapplication''librars''Doctrine'' ORM''Query''Parser.phpDoctrine''ORM''Query''Parser->semanticalError('Class'Userss'…',Array)#2 C:''xamplep''htdocs''hotell''application''libraries''Doctrine''ORM''Query''Passer.php(1529):Doctrine'' ORM''Query''Parser->AbstractSchemaNameC: ''axamplep''htdocs''hotell''application''librars''Doctrine''ORM''Query''Parser.php(1173):Doctrine ''ORM''Query ''Parser->IdentificationVariableDeclaration

我的实体代码:

<?php    
namespace Entity;
use Doctrine'Common'Collections'ArrayCollection;
/**
 * @Entity
 * @Table(name="user")
 */
class Userss
{
    /**
     * @Id
     * @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="AUTO")
     */
    public $id;
    /**
     * @Column(type="string", length=32, unique=true, nullable=false)
     */
    public $username;
    /**
     * @Column(type="string", length=64, nullable=false)
     */
    public $password;
    /**
     * @Column(type="string", length=255, unique=true, nullable=false)
     */
    public $email;
    /**
     * The @JoinColumn is not necessary in this example. When you do not specify
     * a @JoinColumn annotation, Doctrine will intelligently determine the join
     * column based on the entity class name and primary key.
     *
     * @ManyToOne(targetEntity="Group")
     * @JoinColumn(name="group_id", referencedColumnName="id")
     */
    public function setUsername($Username)
    {
      $this->username = $Username;
    }
    public function getUsername()
    {
      return $this->username;
    }
    // and more...
}

这是我在模型中的代码,它从CI_model:扩展而来

<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once APPPATH . 'modules/user/models/entity/user_modell.php';

  class User_model extends CI_Model
  {
    public $em;
    public function __construct() {
      parent::__construct();
      $this->em = $this->doctrine->em;
    }

    function test()
    {
      $repo = $this->em->getRepository('Entity''Userss', 'u');
      $qb = $repo->createQueryBuilder('u')
                 ->select('u.username, u.password, u.email')
                 ->from('Userss', 'u')
                 ->orderBy('u.username', 'ASC')
                 ->getQuery()->getArrayResult();
      var_dump($qb);
      die;
    }
  }

尝试更改

->getQuery()->getArrayResult(); 

进入

->getQuery()->getResult();

它对我有效。