codeingiter 1.5.4 and EXTJS 2.0.1 |
[eluser]olavski[/eluser]
CodeIgniter works like a dream with ExtJS. The only thing I've done to "integrate" extjs is to set up a library class that will handle the JSON output for both php 4 and 5. <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require "json/JSON.php"; class MY_Json extends Services_JSON{ function sendJSONsuccess($responseText = "", $data_a = "") { $ajax_res = array( "responseText" => $responseText, "success" => "true", ); if (is_array($data_a)) $ajax_res = array_merge($ajax_res, $data_a); $this->sendJSON($ajax_res); } function sendJSONfailure($responseText = "", $data_a = "") { $ajax_res = array( "responseText" => $responseText, "success" => "false", ); if (is_array($data_a)) $ajax_res = array_merge($ajax_res, $data_a); $this->sendJSON($ajax_res); } function sendJSON($json_array) { if (function_exists('json_encode')){ $json_str = json_encode($json_array); } else{ $json_str = $this->encode($json_array); } header("Content-length: ". strlen($json_str)); echo $json_str; exit; } } ?> Get the JSON.php class from PEAR: http://pear.php.net/pepr/pepr-proposal-show.php?id=198 Then add 'my_json' to the autoload libraries. $autoload['libraries'] = array('database', 'my_json'); The controller function can be something like this: function getSomeList() { $some_a = Array(); $query = $this->db->query("SELECT some_id, some_name FROM some_list"); foreach ($query->result_array() as $row) $some_a[] = $row; $ajax_res = array( "totalCount" => count($some_a), "some_a" => $some_a, ); $this->my_json->sendJSON($ajax_res); } The ExtJS javascrip code to load that data into a data store would then be: some_ds = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: 'index.php?c=lists&m=getSomeList' }), // create reader that reads the Topic records reader: new Ext.data.JsonReader({ root: 'some_a', totalProperty: 'totalCount', id: 'some_id' }, [ {name: 'some_id', mapping: 'some_id'}, {name: 'some_name', mapping: 'some_name'} ]), // turn on remote sorting remoteSort: true }); some_ds.load(); A bit messy but hope some of this helps... |
Messages In This Thread |
codeingiter 1.5.4 and EXTJS 2.0.1 - by El Forum - 02-04-2008, 11:34 AM
codeingiter 1.5.4 and EXTJS 2.0.1 - by El Forum - 02-05-2008, 01:03 PM
codeingiter 1.5.4 and EXTJS 2.0.1 - by El Forum - 02-18-2008, 08:34 AM
codeingiter 1.5.4 and EXTJS 2.0.1 - by El Forum - 02-18-2008, 01:21 PM
codeingiter 1.5.4 and EXTJS 2.0.1 - by El Forum - 02-18-2008, 05:07 PM
codeingiter 1.5.4 and EXTJS 2.0.1 - by El Forum - 02-19-2008, 05:42 PM
codeingiter 1.5.4 and EXTJS 2.0.1 - by El Forum - 06-11-2008, 02:15 PM
|