Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I prefer to use widget or renderPartial in Yii's view?

Tags:

yii

I am confused when I should use a custom widget or renderPartial in my view files. Sometimes I use widget and sometimes I use renderPartial.

like image 383
Onkar Janwa Avatar asked Jul 05 '12 13:07

Onkar Janwa


2 Answers

Widget

You use widget when your application logic is defined in a separate CLASS file and the logic is somehow separated and standalone.

Widget's are chosen when the functionality is repeatedly used elsewhere, on lot of pages.

renderPartial

You use renderPartial for VIEW files that you want to embed into something bigger, or when you want to print something without using the application layouts.

renderPartial is chosen when all the variables it need to access are already prepared in the current action.

like image 123
Pentium10 Avatar answered Oct 19 '22 03:10

Pentium10


Widget You can use widget when your site has some common part like header and footer or sometime some kind filter which require on every page of site.

renderPartial Take example of search form of yii crude which is called by using renderPartial because that serach form is changing according to requirement of pages.

Sorry for english.

like image 24
Rohit13 Avatar answered Oct 19 '22 02:10

Rohit13