PDA

View Full Version : Changing URL of a store at runtime



RollingFred
21 Sep 2010, 8:09 PM
I have multiple forms with comboboxes.
Some of those comboboxes are linked to a XMLStore with a URL = "http://localhost..."
When I publish my application on PROD, I'd like those URL to be "http://servername...."

I tried multiple combinations, ended up having to modify the auto-generated Store JS file:



// BEFORE
storeCodeline = Ext.extend(Ext.data.XmlStore, {
constructor: function(cfg) {
cfg = cfg || {};
storeCodeline.superclass.constructor.call(this, Ext.apply({
storeId: 'storeCodeline',
url: 'http://localhost/KO/admin/store/store/formAction?action=getStoreCodelineLookupTable',
record: 'Codeline',
idPath: 'Name',
totalProperty: '@total',
fields: [
{
name: 'Name',
mapping: 'Name'
}
]
}, cfg));
}
});
new storeCodeline();

//AFTER
storeCodeline = Ext.extend(Ext.data.XmlStore, {
constructor: function(cfg) {
cfg = cfg || {};
storeCodeline.superclass.constructor.call(this, Ext.apply({
storeId: 'storeCodeline',
// getURLPrefix() is defined in the main PHP page and return the correct prefix
url: getURLPrefix() + 'admin/store/store/formAction?action=getStoreCodelineLookupTable',
record: 'Codeline',
idPath: 'Name',
totalProperty: '@total',
fields: [
{
name: 'Name',
mapping: 'Name'
}
]
}, cfg));
}
});
new storeCodeline();


I'm sure there must be a way to modify the URL generated by the Designer, but cannot find how. The shortcut I put in place is temporary until one of you all give me the magical lines of code...

Thanks in advance

RollingFred
23 Sep 2010, 7:09 AM
Anybody has a solution?

I hate to have to recode this "workaround" each time I'm clicking Export Project

jarrednicholls
23 Sep 2010, 1:24 PM
RollingFred,

You can just give the HttpProxy a new url. Try this:



var store = Ext.StoreMgr.lookup('storeCodeline');
store.proxy.url = getURLPrefix() + 'admin/store/store/formAction?action=getStoreCodelineLookupTable';

madirishman
16 Dec 2010, 8:26 AM
Who's method is "getURLPrefix()"? I can't seem to find it.

RollingFred
16 Dec 2010, 8:48 AM
It's mine.
It's a javascript function returning the good protocol/servername/ based on where I publish my application. This is a JS function that I generate from PHP.
This is based on my own code so I doubt you can reuse it, but you can always define your own.



function getURLPrefix()
{
// A bit crappy but works. url::site is a KohanaPHP function
return '<?= substr(url::site('p'),0,strlen(url::site('p'))-1) ?>';
};

madirishman
16 Dec 2010, 9:21 AM
ahhh, clever! thanks!