Skip to content Skip to sidebar Skip to footer

Yii - Ways To Do Include Another View In This View

My layout page:

    Solution 1:

    If I understand your question right, you can do a few things...

    (I am assuming that you have a partial view file like views/model/_list.php.)

    You can either renderPartial('/model/_list') on the initial page load, and then in your AJAX action just call renderPartial('/model/_list') again.

    Or you can just have the AJAX action (containing renderPartial('/model/_list')), and call it on page load with jQuery instead of rendering it in the view (just call Yii::app()->getClientScript()->registerScript in your view where you want to load it, and use $.ajax() or something to make the call).

    A third thing that I have done is make a function in the controller (not an action, just a regular public method) that returns the output of renderPartial (return $this->renderPartial('/model/_list',array(), true) I think). Then in view on the initial load I echo that function, and in the ajax action I echo it before calling Yii::app()->end();.

    Widgets are useful when you will be rendering a bit of partial code all over the site, even on pages from different controllers. So if that list is in a sidebar all over the site it might be better to make a widget out of it, otherwise I would just use the controller of the model you are working with. What you would do with the widget is the same as you would with the regular view - either build the data in the Widget and render the partialView, or call it via AJAX. What you would probably do for the AJAX is POST to the controller you are getting the data from, so you will still need the AJAX action. The widget will just make it easier to drop it different places around the site.

    Good luck!

    Post a Comment for "Yii - Ways To Do Include Another View In This View"