Zend框架结果集

时间:2014-02-11 16:13:51

标签: zend-framework

您好我正在尝试像Album示例一样实现fetchAll方法,但它不起作用。 当我尝试用var_dump打印结果时,我得到了这个

object(Zend\Db\ResultSet\ResultSet)#258 (8) {
      ["allowedReturnTypes":protected]=>
      array(2) {
        [0]=>
        string(11) "arrayobject"
        [1]=>
        string(5) "array"
      }
      ["arrayObjectPrototype":protected]=>
      object(Application\Model\Ubigeo)#242 (5) {
        ["codDpto"]=>
        NULL
        ["codProv"]=>
        NULL
        ["codDist"]=>
        NULL
        ["name"]=>
        NULL
        ["idUbigeo"]=>
        NULL
      }
      ["returnType":protected]=>
      string(11) "arrayobject"
      ["buffer":protected]=>
      NULL
      ["count":protected]=>
      int(2057)
      ["dataSource":protected]=>
      object(Zend\Db\Adapter\Driver\Pdo\Result)#257 (8) {
        ["statementMode":protected]=>
        string(7) "forward"
        ["resource":protected]=>
        object(PDOStatement)#248 (1) {
          ["queryString"]=>
          string(52) "SELECT `ubigeo`.* FROM `ubigeo` ORDER BY `name` DESC"
        }
        ["options":protected]=>
        NULL
        ["currentComplete":protected]=>
        bool(false)
        ["currentData":protected]=>
        NULL
        ["position":protected]=>
        int(-1)
        ["generatedValue":protected]=>
        string(1) "0"
        ["rowCount":protected]=>
        int(2057)
      }
      ["fieldCount":protected]=>
      int(5)
      ["position":protected]=>
      int(0)
    }

这是我的serviceConfig:

 public function getServiceConfig() {
    return array(
        'factories' => array(
            'Application\Model\UbigeoTable' => function ($sm) {
                $tableGateway = $sm->get('UbigeoTableGateway');
                $table = new UbigeoTable($tableGateway);
                return $table;
            },
            'UbigeoTableGateway' => function ($sm) {
                $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                $resultSetPrototype = new ResultSet();
                $resultSetPrototype->setArrayObjectPrototype(new Ubigeo());
                return new TableGateway('ubigeo', $dbAdapter, null, $resultSetPrototype);
            }
        ),
    );
}

任何帮助都会受到赞赏

1 个答案:

答案 0 :(得分:0)

根据var_dump,您的表包含以下行: codDpto codProv codDist name idUbigeo

您可以通过以下方式访问结果:

foreach($resultSet as $row)
{
    $result = '<p>codDpto: '.$row['codDpto'];
    $result .= ', codProv: '.$row['codProv'];
    $result .= ', codDist: '.$row['codDist'];
    $result .= ', name: '.$row['name'];
    $result .= ', idUbigeo: '.$row['idUbigeo'].'</p>';

    echo $result;
}