1
我想弄清楚如何使用JSON顯示Ajax的幾個元素。我跟着此Using ajax in zend framework 2和外翻工作正常,但現在希望通過JSONZend 2 Ajax JSON多個數據
通過例如10目的在JSpublic function indexAction()
{
$result = new JsonModel (array(
'fototable' => $this->FotoTable->getFotos()
)
);
return $result;
}
,然後循環和顯示數據。問題是如果我做了上面的代碼。我沒有得到任何Json輸出。我試圖序列化數據,但是我得到的錯誤是無法序列化PDO陳述。
這裏是我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);
}
}
你能還與getFotos()方法分享Footable類簽名? – edigu 2014-11-22 10:46:46
剛剛編輯帖子 – user3544190 2014-11-22 12:58:56