如何获得所有材料的ID?

时间:2013-10-06 17:12:02

标签: symfony symfony-2.3

帮帮我

public function indexAction() 
{


$tpos = $this->getDoctrine()->getRepository('TestBundle:Materials')->findAll();

foreach($tposs as $tpos) {
     $posts['id'];
} 

echo $midcount;
你会怎么做?

注意:未定义索引:id

1 个答案:

答案 0 :(得分:1)

$materials = $this->getDoctrine()->getRepository('TestBundle:Materials')->findAll();
$materialIds = array();
foreach ($materials as $material) {
    $materialIds[] = $material->getId();
}