2012-08-09 2 views
0

comment convertir objet Zend_Db_Table_Rowset à javascript tableauComment convertir objet Zend_Db_Table_Rowset à javascript tableau

$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(); 


} 

} Je veux convertir le jeu de résultats pour quelque chose liket ceci:

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

Où est le piège? Juste 'foreach' sur le jeu de lignes, non? – bububaba

Répondre

1

JSON s'adapte bettew pour de telles opérations

intérieur contrôleur

$db=new Application_Model_DbTable_Books(); 
$result=$db->showBooks();  
$this->view->booksJson = Zend_Json::encode($result); 

Inside script de vue

var aDataSet = JSON.parse(<?php echo $this->booksJson;?>); 
Questions connexes