調用所有的干將使用後:
從實體
$queryResult =
$this
->getDoctrine()
->getRepository('EtecsaAppBundle:Paralizacion')
->createQueryBuilder('e')
->getQuery();
->setDQL($myOwnQuery)
->getResult();
我有,我想用自己的全部財產的getter實體的數組。我這樣做是這樣的:
foreach ($queryResult as $index => $itemEntity)
{
$objWorksheet->SetCellValue('A'. ($index + 17), $index + 1);
// ... The itemEntity class has entity relationships associations
$objWorksheet->SetCellValue('B'. ($index + 17), $itemEntity->getSomeRelatedProperty()->getSomeProperty());
// ... it also has properties with several types (date, string, etc)
$objWorksheet->SetCellValue('C'. ($index + 17), $itemEntity->getSomeProperty));
// Also some of the values obtained from his respective getter require some processing
$objWorksheet->SetCellValue('D'. ($index + 17), getProcessedValue($itemEntity->getSomeSpecificProperty));
}
在SetCellValue函數中使用的字母也會增加。我以此爲例。 有沒有辦法動態調用實體的所有getter,所以我不必一個一個的打電話給他們?這樣的例如:
foreach ($queryResult as $index => $itemEntity)
{
$columnLetter = 'A';
$objWorksheet->SetCellValue($columnLetter++ . ($index + 17), $index + 1);
arrayOfGetters = getArrayOfGetters(itemEntity);
foreach (arrayOfGetters as $getterMethod)
{
// properties that reference an entity relationship association would have the __ToString function
$objWorksheet->SetCellValue($columnLetter++ . ($index + 17), /* get value of getterMethod */);
}
}
而問題是什麼? –
@JovanPerovic 對不起......我要求一種方式來動態調用實體的所有獲取者,所以我不必一一給他們打電話 –
我認爲人們對你的問題投下了一票,因爲它是有些模糊。我認爲你的問題的癥結在於標題(因此我提交了答案),但是下面的內容「SetCellValue函數中使用的字母也會增加」問題的一部分?如果是這樣,請澄清,我會盡力相應地更新我的答案。 –