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



我在此代码之后有此错误:

此结果是仅向前的结果集,不支持在向前移动后调用 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>";
                                }
                            }
                        }

控制器.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(),
    ));
}

用户功能表.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;
}

公司表.php

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

为什么我无权嵌入我的两个"foreach ()"?

您需要缓冲结果。

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

相关内容

最新更新