I have a problem:
I am using doctrine 2 and codeigniter 2. I want to know how does doctrine query builder work? I want to use select
query on doctrine query builder, but I can't do it. I've also read doctrine documents and tried, but I was not successful.
After trying this, I get this error message :
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT u.username, u.password, u.email FROM Entity\Userss u, Userss u ORDER BY u.username ASC' in C:\xampp\htdocs\hotell\application\libraries\Doctrine\ORM\Query\QueryException.php:39 Stack trace: #0 C:\xampp\htdocs\hotell\application\libraries\Doctrine\ORM\Query\Parser.php(429): Doctrine\ORM\Query\QueryException::dqlError('SELECT u.userna...') #1 C:\xampp\htdocs\hotell\application\libraries\Doctrine\ORM\Query\Parser.php(854): Doctrine\ORM\Query\Parser->semanticalError('Class 'Userss' ...', Array) #2 C:\xampp\htdocs\hotell\application\libraries\Doctrine\ORM\Query\Parser.php(1529): Doctrine\ORM\Query\Parser->AbstractSchemaName() #3 C:\xampp\htdocs\hotell\application\libraries\Doctrine\ORM\Query\Parser.php(1426): Doctrine\ORM\Query\Parser->RangeVariableDeclaration() #4 C:\xampp\htdocs\hotell\application\libraries\Doctrine\ORM\Query\Parser.php(1173): Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration() #5 C:\xampp\htdocs\hotell\applic in C:\xampp\htdocs\hotell\application\libraries\Doctrine\ORM\Query\QueryException.php on line 49
My entity code:
<?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...
}
and this is my code in model that extends from 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;
}
}