如何将zend_db_table_rowset对象转换为javascript数组
$db=new Application_Model_DbTable_Books();
$result=$db->showBooks();
showBooks:
class Application_Model_DbTable_Books extends Zend_Db_Table_Abstract
{
protected $_name = 'books';
protected $_primary = 'id';
public function showBooks(){
return $this->fetchAll();
}
} 我想将结果集转换为以下内容:
var aDataSet = [
['Trident','Internet Explorer 4.0','Win 95+','4','X'],
['Trident','Internet Explorer 5.0','Win 95+','5','C'],
['Trident','Internet Explorer 5.5','Win 95+','5.5','A'],
['Trident','Internet Explorer 6','Win 98+','6','A']];
答案 0 :(得分:1)
JSON适合此类操作
内部控制器
$db=new Application_Model_DbTable_Books();
$result=$db->showBooks();
$this->view->booksJson = Zend_Json::encode($result);
内部视图脚本
var aDataSet = JSON.parse(<?php echo $this->booksJson;?>);