我有收集表单,需要访问我在视图中显示的值。问题似乎是声明为Integer的关键变量,我得到了这样的错误:
无法访问整数变量的属性(" nama")(" 0") 在SifoAdminBundle:DftAbsensi:第65行的manage.html.twig
我的Twig:
{% for key, absensi in form_edit %}
<li>{{ form_edit.vars.value.statusS.key.nama }}</li>
{% endfor %}
如果我将{{ form_edit.vars.value.statusS.key.nama }}
更改为{{ form_edit.vars.value.statusS.1.nama }}
,则其工作正常。
这是我的控制器:
/* Show data */
$emShow = $this->getDoctrine()->getManager();
$collectionAbsensi = new CollectionAbsensi();
foreach ($entityGrupPelajar as $temp) {
$entity = new DftAbsensi();
$entity = $emShow->getRepository('SifoAdminBundle:DftAbsensi')->findOneBy(array('idGrupPelajar' => $temp, 'tanggal' => $tanggal));
if ($entity)
{
$entityPelajar = $emShow->getRepository('SifoAdminBundle:MstPelajar')->find($temp->getIdPelajar());
$dftAbsensi = new DftAbsensi();
$dftAbsensi->setId($entity->getId())
->setIdGrupPelajar($entity->getIdGrupPelajar())
->setTanggal($entity->getTanggal())
->setStatus($entity->getStatus())
->setNis($entityPelajar->getNis())
->setNama($entityPelajar->getNama())
;
$collectionAbsensi->getStatusS()->add($dftAbsensi);
}
}
$emShow->flush();
$formEdit = $this->createForm(new CollectionAbsensiType(), $collectionAbsensi);
$formEdit->add('save', 'submit', array('attr' => array('class' => 'btn btn-info')));
return $this->render('SifoAdminBundle:DftAbsensi:manage.html.twig', array(
'form_edit' => $formEdit->createView(),
));
我搜索过这个问题也读了#902但问题仍然出现在我的PHP 5.4上的Symfony 2.4中
有没有办法在没有密钥的情况下在迭代中获得该值?
答案 0 :(得分:3)
尝试更改
form_edit.vars.value.statusS.key.nama
要
form_edit.vars.value.statusS[key].nama
前者相当于$form_edit['vars']['value']['statusS']['key']['nama']
(不存在),而后者相当于$form_edit['vars']['value']['statusS'][$key]['nama']