ZEND此结果是仅向前结果集,不支持向前移动后调用rewind()

时间:2016-02-23 16:31:37

标签: zend-framework2

我在此代码之后出现此错误:

  

此结果是仅向前结果集,不支持在向前移动后调用rewind()。

Page.phtml:

foreach ($company as $key => $value) 
                        {
                            foreach ($userfeature as $key => $data)
                            { 
                                echo "<tr>";
                                if($value->site_id == $data->site_id)
                                {
                                    echo "<td>".$value->party_code." ".$value->party_name. "</td>";
                                }
                            }
                        }

Controller.php这样

public function indexsiteuserAction()
{
    $this->layout('layout/admin');
    $compteAdmin[] = $this->admincompte();
    $user_id = (int) $this->params()->fromRoute('id', 0);
    if (!$user_id) 
    {
        return $this->redirect()->toRoute('administrateur', array('action' => 'adduser'));
    }
    try 
    {
        $user = $this->getUserTable()->getUser($user_id);
        $userfeature = $this->getAdminUserFeatureTable()->afficheruserFeature($user_id);
    }
    catch (\Exception $ex) 
    {
        return $this->redirect()->toRoute('administrateur', array('action' => 'indexuser'));
    }

    return new ViewModel(
        array(
            'user_id' => $user_id,
            'user'=> $user,
            'userfeature' => $userfeature,
            'compteAdmin' => $compteAdmin,
            'company' => $this->getCompanyTable()->fetchAll(),
    ));
}

Userfeaturetable.php

    public function getUserFeature($user_id)
{
    $user_id  = (int) $user_id;
    $rowset = $this->tableGateway->select(array('user_id' => $user_id));
    $row = $rowset->current();        
    if (!$row) 
    {
        throw new \Exception("Could not find row $user_id");
    }
    return $row;
}

companyTable.php

public function fetchAll()
{
    $resultSet = $this->tableGateway->select();
    return $resultSet ;
}

为什么我没有权利嵌入我的两个'foreach()'?

1 个答案:

答案 0 :(得分:0)

您需要缓冲结果。

public function fetchAll()
{
    $resultSet = $this->tableGateway->select();
    $resultSet->buffer();

    return $resultSet ;
}