Zend \ Db \ ResultSet \ ResultSet对象在哪里存储检索到的数据?

In a Zend Framework application, that is built pretty similar to the album application from the ZF2 Getting Started tutorial, I use a ResultSet object to transport the data from the model over the controller to the view (for details see the code below).

This works fine, but I don't get, where the ResultSet object holds the data. I can loop it e.g. with foreach and get the data row byrow (or better model object by model object). But when I debug it in my IDE or simply with var_dump(...), it seems to be empty.

How/where does a Zend\Db\ResultSet\ResultSet object hold the data, retrieved from the database?

The relevant parts of the code:

Module settings:

class Module implements ConfigProviderInterface, ServiceProviderInterface, AutoloaderProviderInterface {
...
    public function getServiceConfig() {
        try {
            return array (
                'factories' =>array(
                    ...
                    'SportTable' => function ($serviceManager) {
                        $tableGateway = $serviceManager->get('SportTableGateway');
                        $table = new SportTable($tableGateway);
                        return $table;
                    },
                    'SportTableGateway' => function ($serviceManager) {
                        $dbAdapter = $serviceManager->get('Zend\Db\Adapter\Adapter');
                        $resultSetPrototype = new ResultSet();
                        $resultSetPrototype->setArrayObjectPrototype(new Sport());
                        return new TableGateway('sports', $dbAdapter, null, $resultSetPrototype);
                    },
                    ...
                )
            );
        }
        ...
}

Model (table):

class CourseTable {
        ...
    public function findAllByCityNameAndSportTitle($cityName, $sportTitle) {
        $select = new Select();
        $where = new Where();
        ...
        $resultSet = $this->tableGateway->selectWith($select);
        return $resultSet;
    }
    ...
}

Model (mapper):

class Course implements ArraySerializableInterface {

    public $id;
    ...

    public function exchangeArray(array $data) {
        $this->id               = (isset($data['id'])) ? $data['id'] : null;
        ...
    }
    ...
}

Controller:

class CatalogController extends AbstractActionController {
    ...
    public function listCoursesAction() {
        $cityName = $this->params()->fromRoute('city', null);
        $sportTitle = $this->params()->fromRoute('sport', null);
        return new ViewModel(array(
            'city' => $cityName,
            'sport' => $sportTitle,
            'courses' => $this->getCourseTable()->findAllByCityNameAndSportTitle($cityName, $sportTitle)
        ));
    }
    ...
}

View:

<?php foreach ($courses as $course) : ?>
<div>
    <div>id: <?php echo $this->escapeHtml($course->id); ?></div>
    ...
</div>
<?php endforeach; ?>

Zend\Db\ResultSet\ResultSet or rather Zend\Db\ResultSet\AbstractResultSet is holding the answer to your question. This object has 10-12 methods most of them providing iterative functionality. To answer your question the Zend\Db\ResultSet\ResultSet holds the information retrieved from the Db in its dataSource paramter (Zend\Db\ResultSet\ResultSet::$dataSource).

The paradox of results being iterated and loaded with foreach but not seen by var_dump() can be explained by the fact that the results returned are actually hold in buffered.

If you want to access the result set I suggest you to use Zend\Db\ResultSet\ResultSet::toArray() ($resultSet->toArray()). This will return an array of arrays where each array is a row in the DB table.

Hope this helps, feedback will be appreciated :),

Stoyan.