I have an application built using the Zend Framework. I decided to go with jQuery instead of Dojo. I use ZendX helpers for things like ajaxLinks and dialogContainers. I want to try to make the GUI as possible AJAX. But I struggle to decide how I feel, this is the best approach. In most cases, it is a matter of loading the "page" in the dialogContainer instead of reloading the entire page. So that you, for example, get a dialog containing a form for changing some user data or something like that.
At first I returned the whole page, but if it was requested using an AJAX request, it used a different layout template to avoid all unenecerry javascript inclusions, etc. This allowed me to create one version of the page, which would basically be viewable, as usual And through AJAX. But I did not convince myself that I like it. Looking at the Zend Server GUI, they seem to do it, although they don’t return json-encoded data and build a page from it.
What would be the best approach for this and how should I handle javascript that is specific to the restored page? Now I have all the page specific javascript in the phtml file of this page.
Another thing I'm worried about is keeping track of resources created when opening a large number of dialog containers and filling them through ajax. Let's say we open one dialog and get a list of elements. If we click one more pop-up pop-up flag of the modal dialog box for this particular element and populate through ajax. But if the main page never reloads, I see that it becomes difficult to handle.
It seems like I can't be the first to want to make an ajax-driven user interface, so please point me in the right direction before I draw myself in the corner .;)
Update. I tried all kinds of tutorials that I could find on the topic of context, as well as on the documentation in Zend. I think I must have missed to include some kind of undocumented function or something like that. Since this did not work, I deleted the code, but tried to find the examples that I was looking at before I tried things like the following code.
$ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('list', 'html') ->addActionContext('modify', 'html') ->initContext();
And I tried something like the following
$this->_helper->contextSwitch() ->setContext('html', array( 'suffix' => 'html', 'headers' => array('Content-Type' => 'text/html; Charset=UTF-8'), ) ) ->addActionContext('index', array('html','xml', 'json')) ->setAutoJsonSerialization(true) ->initContext();
I tried to add other ActionContexts etc., but no matter what they all just ended up displaying a regular .phtml file all the time.