PDA

View Full Version : Getting Server Side Variables Into Your ExtJS Files



Clever Cutter
15 Dec 2009, 5:58 AM
Normally when I build ExtJS apps I'm using a Zend Framework back end. The server back end is largely irrelevant to my inquiry, however. What I usually do is serve up the ExtJS files as view files and render them using the framework's built in template renderer. This allows me to inject PHP variables right into the ExtJS JavaScript files. This is convenient and fast. However, a big drawback is that when I try to use a minifier like Google's closure it chokes on the PHP tags and prevents me from getting a minified version of my ExtJS source code. Not to mention it just doesn't seem like it's best practices to do such a thing.

If I'm correct in my assumption, what is a better way of doing this? Is it having an AJAX call just to grab server side variables? Or maybe instead of serving up static ExtJS to the browser I use a minifier that executes right before the page is served and therefor the PHP variables are already output so the minifier is only parsing the final JavaScript?

I'd be interested to hear your thoughts on this. Thank you.

tubamanu
15 Dec 2009, 7:08 AM
i m currently developing an mulitlanguage application using extjs and symfony 1.3.

I've tested using PHP Tags in JS ExtJS Files and then use these files as View components.
I also tested to add the serverside variables using an ajax request. This works fine and i think it was the fastest solution when trying to load the whole page.
Another way i tested was to add the serverside values in htlm hiddenfields and then get access using extjs. but this is quite a unsafe solution.

finally i'm using your solution with the php tags, cause extjs was creating some trouble with special chars languages.........

but u can also load your serverside variables using ajax at the entry point of your extjs application....