【发布时间】:2014-11-29 10:14:02
【问题描述】:
我正在尝试将数据从我的数据库返回到 Zend Framework 2 中的 JSON。我现在正在使用 TableGateway,它返回一个 ResultSet。但是 JsonModel 无法显示结果集。 那么有没有办法转换它,或者有没有其他方法可以访问我的数据库?
HomeController 中的 IndexAction
public function indexAction()
{
return new JsonModel(array(
'posts' => $posts,
'resources' => $resources,
'style' => $style,
'imgStyle' => $imgStyle,
'success' => true,
));
}
返回结果集的函数
public function fetchAll()
{
$resultSet = $this->tableGateway->select(function (Select $select) {
$select->order('date DESC');
});
return $resultSet;
}
【问题讨论】:
标签: php json zend-framework2