Passando dados da classe PHP para PHPExcel via AJAX
@i ficou preso com os dados PHP e json do OOP. Eu não sou completamente novo no OOP, mas não consigo entender isso. se alguém puder me explicar, seria ótimo!
i tenho o seguinte objeto de grade no PHP:
Class Grid {
var $data;
var $joins;
var $fields;
var $where;
var $table;
var $groupBy;
var $having;
var $limit;
var $order_by;
var $sort;
var $security;
var $set;
var $sql;
....
// loads data into the grid
function load() {
...
// setup the sql - bring it all together
$sql = "
SELECT $post[cols]
FROM `$table`
$joins
$where
$groupBy
$having
ORDER BY $order_by $sort
$limit
";
$this->sql = $sql;
// execute the sql, get back a multi dimensial array
$rows = $this->_queryMulti($sql);
// form an array of the data to send back
$data = array();
$data['rows'] = array();
foreach($rows as $i=>$row) {
foreach($row as $col=>$cell) {
// use primary key if possible, other wise use index
$key = $primaryKey ? $row[$primaryKey] : $i;
// primary key has an _ infront becuase of google chrome re ordering JSON objects
//http://code.google.com/p/v8/issues/detail?id=164
$data['rows']["_".$key][$col] = $cell;
}
}
...
$data['order_by'] = $order_by;
$data['sort'] = $sort;
$data['page'] = $page;
$data['start'] = $startRow + 1;
$data['end'] = $startRow + $nRowsShowing;
$data['colData'] = $colData;
$this->data = $data;
}
e é chamado por AJAX callgrid.php:
$grid->load();
// here we need to add field in data[sql] = sql query, then we can pass it to toExcel() - how?
echo json_encode($grid->data);
O que estou tentando obter é poder exportar a consulta sql atual (pode ser tudo ou resultados pesquisados) para o Excel usando PHPExcel. Então, eu tenho o toExcel.php com a função toexcel ($ query) - que pegará uma consulta e a exportará para o Exce
gora - como passar a consulta sql da grade para toexcel via AJA
Entendo que preciso adicionar a $ data ():
$ data ['sql'] = $ sql;
qual o proximo
UPDATE: estou usando a seguinte grade jquery:http: //square-bracket.com/openj
Entendo que o PHPExcel deve ser iniciado por grid ou jquery