0
在我的模型,我有:ZF2 - 循环的循环
public function fetchForParentId($id)
{
$resultSet = $this->tableGateway->select(array('acl_menu_parent_id' => $id));
$resultSet->buffer();
$resultSet->next();
return $resultSet;
}
和控制器:
$sm = $this->getServiceLocator();
$this->layout()->acl_menu = $sm->get('AdminSettings\Model\AclMenuTable');
在我看来,我可以用模型功能:
<?php
$rows = $this->acl_menu->fetchForParentId(0);
foreach ($rows as $item):
echo $item->acl_menu_name.'<br>';
endforeach;
?>
它的工作原理,但如果我尝试运行此:
<?php
$rows = $this->acl_menu->fetchForParentId(0);
foreach ($rows as $item):
echo $item->acl_menu_name.'<br>';
$subRows = $this->acl_menu->fetchForParentId($item->acl_menu_id);
foreach ($subRows as $subItem):
echo ' - '.$subItem->acl_menu_name.'<br>';
endforeach;
endforeach;
?>
第二个foreach不起作用,$ rows-> acl_menu_id存在,而在数据库中有正确的行显示。
我不知道它为什么会发生。
对不起我的错,是完全按照你写的,而不是作品。 – Nizzre
好的,我重写了第二个foreach,现在没关系。一些空白?没关系。感谢您的时间。 – Nizzre