View我的意思是:最简单的方法来获取查询对象的数组中的symfony
create view `vMaketType` as select * from MaketType
我有一个view在数据库,但由于教条的,现在不能支持它,使用查询我,并一个接一个地取出它:
$em = $this->getDoctrine()->getManager();
$con = $this->getDoctrine()->getEntityManager()->getConnection();
$stmt = $con->executeQuery('SELECT * FROM vMaketType');
$domain = [];
//I must fetch it and set it one by one
foreach ($stmt->fetchAll() as $row){
$obj = new vMaketType();
$obj->setId($row["Id"]);
$obj->setName($row["Name"]);
$obj->setAmount($row["Amount"]);
array_push($domain, $obj);
}
对我来说这真的需要太多的时间来逐个编码。
vMaketType是自定义实体我创建了从控制器发送数据到[Twig]视图。
有没有更简单的方法来获取对象vMaketType数组?
因为我有24个字段的视图,我希望有更简单的方法。
为什么你不使用MarketType(我假设这是你的实体与映射信息)? – ccKep
他说这不适用于sql视图,但我不明白为什么:检出:https://stackoverflow.com/questions/8377671/how-to-set-up-entity-doctrine-for-database -view-in-symfony-2 –
我使用ORM生成模式 – yozawiratama