I am trying to return data from my database to JSON in Zend Framework 2. I am using a TableGateway right now and it returns a ResultSet. But the JsonModel cannot show the resultset. So is there a way to convert it, or is there an other way to access my database?
The IndexAction in the HomeController
public function indexAction()
{
return new JsonModel(array(
'posts' => $posts,
'resources' => $resources,
'style' => $style,
'imgStyle' => $imgStyle,
'success' => true,
));
}
The function that returns the resultset
public function fetchAll()
{
$resultSet = $this->tableGateway->select(function (Select $select) {
$select->order('date DESC');
});
return $resultSet;
}