Revision #4 has been created by Manish Gupta on Oct 31, 2013, 9:00:35 AM with the memo:
embed the image instead of linking to it
« previous (#3)
Changes
Title
unchanged
Rendering Views and Updating them with Ajax
Category
unchanged
Tips
Yii version
unchanged
Tags
unchanged
yii, rendering, renderPartial, Widgets, jQuery, JSON, update, refresh
Content
changed
[...]
My case study was a simple Dashboard application, where I have two view – left and right in the same page (layout file). The sequence diagram outlines how these two pieces are rendered and how they’re merged with the layout file to generate a page the user will see. I came up with the sequence diagram below.
If the pieces appear unfamiliar to you, you might want to read – Rendering View Files in Yii [here](http://www.larryullman.com/2011/02/15/rendering-view-files-in-yii/ "Rending a View") (if this link get’s deleted, google the title).
![Sequence Diagram](https://www.evernote.com/shard/s82/sh/886ea1f8-4bbe-4afc-a4b4-2ca6fda2ee3e/7eebfd220c0d74d84c8cb700bd724d32/deep/0/Page-Rendering_Ajax-Update-Sequence.png "
Rendering Views and Updating them with AjaxSequence Diagram")
It might be worth mentioning that, the default implementation of the aforementioned widgets, requests the “owning” controller (the one that created the widget) to render it’s entire view again through an Ajax request. When a response arrives, the html response (page) is parsed using jQuery and the section (div) that the widget is interested in is extracted. The widget’s contents are then replaced with the extracted (partial contents) one.
In a typical application’s controller, where one might be displaying several models/views, it might make sense to write a controller that returns just the partially rendered view without any layout applied. This should cut down some time for you depending on how complex your views/models are. This approach, if thought out carefully should also maximize code sharing.[...]