我有3个以下列方式相关的Symfony2实体:
想要根据一段时间呈现具有车牌号,总距离,总燃料,燃料成本,Km / L,总作业的表格报告。 还想对数据库做一个传统的查询,完成所有这些并发布了this问题。你可以在那里看到一些实际的物体。但是,如果我没有错,Symfony2的理念是使用具有所有这些对象的车辆对象来完成它。您认为最好的方法是什么? 只是我不能设法例如上下对象数组。我试过这个:
class ReportsController extends Controller
{
public function renderAction(Request $request)
{
$vehicles = $this->getDoctrine()
->getRepository('TeamERPTransportBundle:Vehicle')->findAll();
$countVehicles = 0;
$countJobsXVehicle = array();
foreach ($vehicles as $vehicle)
{
$VehicleJobs = $vehicle->getJobs();
$countJobsXVehicle[$countVehicles] = 0;
$countVehicles++;
//This piece of code gives the error
foreach ($VehicleJobs as $VehicleJob)
{
$countJobsXVehicle[$countVehicles]++;
}
//I am planing to do the same for Fuel purchase
//$VehicleRefuels = $vehicle->getFuelPurchaces();
//foreach ($VehicleRefuels)
}
}
}
有了这个我得到这个错误:
ContextErrorException: Notice: Undefined index: vehicles in D:\Web\wamp\www\team\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php line 1753
如何让它发挥作用? 谢谢你的帮助!
编辑: 我也试过这个:
class ReportsController extends Controller
{
public function renderAction(Request $request)
{
$vehicles = $this->getDoctrine()->getRepository('TeamERPTransportBundle:Vehicle')->findAll();
$countVehicles = 0;
$countJobsXVehicle[] = 0;
foreach ($vehicles as $vehicle)
{
$VehicleJobs = new ArrayCollection();
$VehicleJobs[] = $vehicle->getJobs();
$countJobsXVehicle[$countVehicles] = $this->VehicleJobs($VehicleJobs);
//$VehicleRefuels = $vehicle->getFuelPurchaces();
//foreach ($VehicleRefuels)
$countVehicles++;
}
}
return $this->render('TeamERPTransportBundle:Transport:report.html.twig', array('vehicles' => $vehicles,
'countJobsXVehicle' => $countJobsXVehicle,
'countVehicles' => $countVehicles,
'render' => $graph));
}
private function VehicleJobs (ArrayCollection $VehicleJobs){
$countJobsXVehicle = 0;
foreach ($VehicleJobs as $VehicleJob)
{
$countJobsXVehicle++;
//var_dump($VehicleJob);
}
return $countJobsXVehicle;
}
}
并且它可以工作,但它的行为不符合预期。 实体条款为here。