次のオブジェクトを含む配列があるとします。
array
0 =>
object(User\Entity\User)[297]
public 'id' => int 1
private 'first_name' => string 'Peter' (length=5)
private 'last_name' => string 'Johnson' (length=7)
private 'initials' => string 'J.J.' (length=4)
private 'email' => string 'test@gmail.com' (length=21)
1 =>
object(User\Entity\User)[296]
public 'id' => int 2
private 'first_name' => string 'Edith' (length=8)
private 'last_name' => string 'Peters' (length=7)
private 'initials' => string 'R.J.' (length=4)
private 'email' => string 'edit@gmail.com' (length=26)
今、私はそれらをテーブルに置きたいです。しかし、私はそれを普遍的にしたいので、抽象的な方法でそれをやろうとしています。
以下の関数に$aColnames配列があり、テーブルに表示したいフィールドの値の取得のみを表示できます。
これは私が構築しようとしている方法です:
private function generateTable()
{
foreach($this->aData as $aData){
$this->sTable.= '<tr>';
foreach($this->aColnames as $sColname){
$this->sTable.= '<td>';
/****What code goes here ****/
$this->sTable.= '</td>';
}
$this->sTable.= '</tr>';
}
}
問題は、オブジェクトから値を取得する方法ではありませんか?毎回オブジェクトをインスタンス化する必要がありますか?誰か助けてくれませんか?