View Full Version : ExtJS inaction: ScriptTagProxy arg formatting, can it be changed?

5 Nov 2010, 10:23 AM
Following the example from chapter 9 with ListView_standalone.html

I want to satisfy this call on my server

extjsinaction.com/getDepartments.php?_dc=1288971967546&callback=stcCallback1001 (http://extjsinaction.com/getDepartments.php?_dc=1288971967546&callback=stcCallback1001)

My server-side is already in place.
I wrote that in CI some time ago: mysite.com/controller/getcats

Looks like I need to fiddle with routing.
But I really don't want to touch/break existing server clients: none using the query string, all using a/r/g/s.

This weekend I want to focus on extJS/UI and not even think about routing and models and query strings. But everything I need on the server side is ready and able but not using query strings...

What are the chances of changing extJS to generate




Is there anywhere I can just fudge it for the weekend?

Or is there a CI guru who has solved this quick n easy like?

Thank you.

5 Nov 2010, 12:14 PM
This is only possible by overriding ScriptTagProxy.doRequest.

5 Nov 2010, 3:23 PM
Ugh there is a simple band-aid below. I guess if I was a regex guru I might attempt it with htaccess.

$s = '';
foreach ($_GET AS $k=>$v)
$s .= '/' . $k . '/' . $v;
$s = '/index.php/controller/myfun' . $s;
header('Location: '.$s);

But many thanks for the reply, exactly the pointer I was looking for.
I guess not looking hard was my first clue: it was gonna be over my head at this time.
And indeed it is.

But wouldn't this make sense as an option, given the proliferation of MVC url-mapped php cms puzzles kicking around...

Anyone say why it's a bad idea, anyone willing to tackle it for me? Case of beer via paypal?

Don't care about proper subclassing yet. A kludge/patch is fine.
Just wanna use my existing server stuff without wrestling query strings or jumping into ExtDirect.


5 Nov 2010, 4:50 PM
As Condor said, it's pretty easy to do:

Ext.override(Ext.data.ScriptTagProxy, {
doRequest : function(action, rs, params, reader, callback, scope, arg) {
var p = Ext.urlEncode(Ext.apply(params, this.extraParams));

var url = this.buildUrl(action, rs);
if (!url) {
throw new Ext.data.Api.Error('invalid-url', url);
url = Ext.urlAppend(url, p);

var transId = ++Ext.data.ScriptTagProxy.TRANS_ID;
var trans = {
id : transId,
action: action,
cb : "stcCallback"+transId,
scriptId : "stcScript"+transId,
params : params,
arg : arg,
url : url,
callback : callback,
scope : scope,
reader : reader
window[trans.cb] = this.createCallback(action, rs, trans);
url = Ext.urlAppend(url, '/dc/' + (new Date().getTime()));
url += String.format("/{0}/{1}", this.callbackParam, trans.cb);
if(this.autoAbort !== false){

trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);

var script = document.createElement("script");
script.setAttribute("src", url);
script.setAttribute("type", "text/javascript");
script.setAttribute("id", trans.scriptId);

this.trans = trans;

6 Nov 2010, 4:00 AM

Cute (short) discussion on overrides here, helped me:


My javascript not yet up to anything complex, I think this will do

if(this.autoAbort !== false){
// begin hack
// Translate url from query format to seo (so can use same server software without extra fuzz)
// eg myhost.com/controller.php?dc=1288971967546&callback=stcCallback1001
// ==> myhost.com/controller/dc/1288971967546/callback/stcCallback1001
// end of hack

If I remember and understand my reading correctly, config items can be passed to constructors.
So it would be a no-brainer to add a switch or event to have this fellow build urls by appending segments instead of query pairs? So I can cope with fads and seo in server software...

Is that bloat or a design headache or a valid feature request ?

8 Nov 2010, 3:18 AM
Here is an update on the javascript that was indeed, "not up to snuff".

// dsm 7 nov 10 : Cannot changer server-side to process query strings at this time.
// We require the controller/function style for our URLs
// cf ExtDirect source for references to Ruby and config property 'restful'
// IE transform http://site.com/foo?fie=foe&fum=blood to http://site.com/foo/fie/foe/fum/blood

url= url.replace(/\?|=|&/g,'/');

Within the override, this is a simple substitution of the final url: replace [?,=,&] with /

url.Append/Apply assumes the format (query vs restful). So I guess that is why the gurus told me to override this function.

How any http formats may there be? Maybe an event (onUrlFormat) rather than a flag. But I need to learn more. Perhaps this logic belongs in the url object, I know not.

In any case, if I can find the correct place to introduce a parameter, I can talk with servers using either scheme: query strings or "restful" strings (/verb/noun/etc).

I have much more reading to do, but it seems the config parameter I am looking for is called "restful".
I think I can add it to the config object in the constructor (but haven't tried that part yet):

var proxy = new Ext.data.ScriptTagProxy({
url : "http://mysite.dev/index.php/extvid/get_cats",
restful : true

Then apply the regex iff restful is true.

Now the silly part is, most of the servers are subdomains on the same server.

I wonder if there isn't a cheat to avoid the overhead of a ScriptTagProxy in that case.

Thank you for your help. Any further tips mighty welcome. So much to know...