If you want to perform a simple SQL query, you can do that :
$con = $this->getDoctrine()->getEntityManager()->getConnection();
$stmt = $con->executeQuery('SELECT * FROM my_views');
foreach ($stmt->fetchAll() as $row){
print_r($row);
}
When you use $em->createQuery()
, you need to work with Doctrine entities.
If you want to use the mapping with your view, juste create an entity :
namespace Your\Bundle\Entity;
/**
* @ORM\Entity
* @ORM\Table(name="my_view")
*/
class MyView
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $someVarcharColumn;
public function getId()
{
return $this->id;
}
public function getSomeVarcharColumn()
{
return $this->someVarcharColumn;
}
}
And you can query it with DQL like this :
$results = $em->createQuery('
SELECT v
FROM YourBundle:MyView v
')->getResult();