Welcome Guest, Not a member yet? Register   Sign In
codeingiter 1.5.4 and EXTJS 2.0.1
#1

[eluser]italoc[/eluser]
i would like to integrate codeingiter 1.5.4 with EXTJS 2.0.1

where i can do?
where i can find a step-by-step tutorial?

it is possible?

thanks
#2

[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...
#3

[eluser]dirkr[/eluser]
[quote author="basslord" date="1202259814"]
A bit messy but hope some of this helps...[/quote]

Thank you - this helped a lot. Just what I needed.

Funny though, that query strings have to be enabled.

This works:
Code:
url: 'index.php?c=lists&m=getSomeList'

and this gives a 404:
Code:
url: 'lists/getSomeList'
#4

[eluser]arthurn[/eluser]
Hi,
this sounds really great and I am about to give it a try. Would you care to share a working controller and a view for testing purposes?
That would speed it up a lot.
Arthur
#5

[eluser]dirkr[/eluser]
[quote author="arthurn" date="1203384094"]Hi,
this sounds really great and I am about to give it a try. Would you care to share a working controller and a view for testing purposes?
That would speed it up a lot.
Arthur[/quote]

You can just use basslords code from above. This includes everything you need. You end up in the view with your data in a data.store which can be used to fill a gridPanel.

Whether it directly works depends on your url routing settings.

If you use the posted code you might have to enable query strings in the configuration.
I used POST with a segment-based url and had to keep the index.php in the url:
Code:
ds = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: '<?php echo base_url()?>index.php/lists/getSomeList.html',
      method: 'post'
    }),
#6

[eluser]arthurn[/eluser]
Thanks, it works fine now, including the post method.
Arthur
#7

[eluser]Yauhen_S[/eluser]
This code looks good, but is not solving problem with PHP errors handling. By default CI return HTML error message, for example if db error occur. And ExtJs cause error when evaling response text. I was try to replace CI errors templates like this:

<?php
$res = array(
'success' => false,
'errors' => array(
'heading' => 'PHP Error:',
'message' => "<p>Severity: $severity; ?&gt;</p>
<p>Message: $message</p>
<p>Filename: $filepath</p>
<p>Line Number: $line</p>"
)
);
print json_encode($res);
?&gt;

but this work if only one error occur, otherwise output come incorrect JSON code




Theme © iAndrew 2016 - Forum software by © MyBB