How to Create A Custom Widget in Yii Framework ?

Yii is a wonderful framework that gives generated codes for the developer.in here I will show you how to create a Custom widget in Yii.

Simplest possible way to get a Custom Widget going:

Then, in a view, you can instantiate it like this: the init()run() methods get called automatically.

Where should I put my custom widget files in Yii framework?

I think the common practice is to put the widget Folder in extensions folder with js & CSS files in a folder named asset. In the PHP class file, you do initialization first by publishing the asset with Yii asset manager.

The file structure may be like
/protected/extensions/MyWidgetdir/assets/
/protected/extensions/MyWidgetdir/views/
/protected/extensions/MyWidgetdir/MyWidget.php

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status