Php Zend 2 Ajax JSON多数据
我试图弄清楚如何使用JSON通过Ajax显示一些元素。我遵循了这一点,everting工作正常,但现在想通过JSON传递示例10对象Php Zend 2 Ajax JSON多数据,php,jquery,ajax,json,zend-framework2,Php,Jquery,Ajax,Json,Zend Framework2,我试图弄清楚如何使用JSON通过Ajax显示一些元素。我遵循了这一点,everting工作正常,但现在想通过JSON传递示例10对象 public function indexAction() { $result = new JsonModel (array( 'fototable' => $this->FotoTable->getFotos() ) ); return $result; } 然后在js中循环并显示
public function indexAction()
{
$result = new JsonModel (array(
'fototable' => $this->FotoTable->getFotos()
)
);
return $result;
}
然后在js中循环并显示数据。问题是如果我执行上述代码。我没有得到任何Json输出。我试图序列化数据,但得到的错误是无法序列化PDO station
这是我的Fototable课程:
<?php
namespace Media\Model;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
use Zend\Db\Adapter\Adapter;
class FotoTable extends TableGateway{
public static $tableName = 'media';
public function addFoto(array $data)
{
return $this->insert($data);
}
public function updateFoto(array $insertData, $id)
{
return $this->update($insertData, array('id' => $id));
}
public function getFotos()
{
$select = new Select();
$select->from(self::$tableName);
$resultSet = $this->selectWith($select);
$resultSet->buffer();
return $resultSet;
}
public function getFotoById($id)
{
$select = new Select();
$select->from(self::$tableName);
$select->where(array('id' => $id));
return $this->selectWith($select)->current();
}
public function getFotosByObject($project)
{
$select = new Select();
$select->from(self::$tableName);
$select->where(array('object_id' => $project));
return $this->selectWith($select);
}
}
中的
返回的结果集不是数组。你可以这样做
return $resultSet->toArray();
有时to array不可用,因此您可以在resultSet上迭代到数组
$array = array();
foreach ($resultSet as $row) {
$array[] = $row
}
return $array;
您还可以使用getFotos()方法共享Footable类签名吗?刚刚编辑了这篇文章
$array = array();
foreach ($resultSet as $row) {
$array[] = $row
}
return $array;