2008年10月18日星期六

Re: [fw-mvc] Zend_Dojo AJAX Requests

Hi Matthew,

I have looked into the code of Zend_Dojo_View_Helper_Dojo_Container, and I think it is possible. The theory is simple:

First I will have to get the Dojo modules that are required, by the getModules() method. Those modules I can give to Zend_Json which puts them into a JSON array. Then, the JavaScript will loop trough all those modules and executes dojo.require() statements for each of them. Also, I can use the getOnloadActions() method to retrieve the scripts for that, which I will push into my JSON response, loop trough them in Javascript and use eval() to execute them. The same I can do with the HeadScript and InlineScript helpers.
Regards,  Pieter Kokx MaakSite.net PHP Developer 


Matthew Weier O'Phinney schreef:
-- Pieter Kokx <pieter@kokx.nl> wrote (on Saturday, 18 October 2008, 04:39 PM +0200):   
Currently I am busy with a project that loads every page with an AJAX request. But that is giving me a problem with Zend_Dojo. When I am using Zend_Form, it will render the Form correctly, but it doesn't load the Dijit form widgets. It is because I can't execute the dojo.require() statements in the AJAX requests. Currently, I am giving some JavaScript with the AJAX response, but I don't know how to retrieve the dojo.require() and onload statements from the dojo view helper.  Does anybody know how I should take this problem and get the dojo.require() and onload statements from the Dojo view helper, so I can include them in the AJAX response and execute them on the client side?     
 You can't, unfortunately; it's a limitation of Javascript.   The way I tackled it with the pastebin demonstration application was to create a Dojo layer that performs all the dojo.require statements I need; this also makes it trivial to create a custom build later to speed the entire application up.  You can see the build file here:      http://github.com/weierophinney/pastebin/tree/master/public/js-src/paste/layer.js  The important aspect is everything up to the first dojo.addOnLoad() statement. If you pay attention to it, basically I'm requiring everything I may possibly need in any XHR requests I make, as well as the requires necessary for the initial page load. When you create a custom build with this layer file, all those will get compiled and in-lined to a single file -- making for a concise, single file with all functionality.    

没有评论: