Load all views in same div

Hello all!

I am starting with Yii2 and I like it (for the moment). I want to know if there are some feature to load all views in same div.

I have a layout with headerbar top, sidebar left and content, I want all views open in content, I can make this with Yii? Or I will have use Ajax to handle this for myself?

I can use renderPartial to skip the layout when the user has entered in my web app, but how I can capture all links and buttons to this works? Any idea?

Thanks

Your problem is not very clear to me but I’ll try to help for what I understood

this handled by the template. The template (dafault position is @app/view/layouts) contain all the information about the page structure, then the view is load in the proper position.

If you open @app/view/layouts/main.php, which is the default layou in yii project you will see a line line




<?= $content ?>



Every view loaded by the controller with the normal method, like:




$this->render('view', ['model' => $model]);



are rendered in this position

I hope I understood correctly your problem and that this solve it.

rrenderPartial output just the view content without layout and assets (javascript and css)

By this I guess you want to change the content using Ajax and widget does not get render correctly:

You have 2 solution:

Use Pajax to change the content at view/template

Normally is used with grid (like for pagination) but it should be possible to use it with the entire page (personally never tried that)

http://www.yiiframew…dgets-pjax.html

Use renderAjax method to render the view.

renderAjax does the same of renderPartial (no layout just the pure view) + i take care of javascript and assets.

Normally this is used when you need to render the content inside a modal. The page is already loaded so the widget loaded in the modal via ajax are not triggered by the




jQuery(document).ready(.....



Practically renderAjax take care of this and of the needed assets.

I will try Pjax then :) Thanks a lot