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

bobo picture bobo · Dec 30, 2011 · Viewed 7.1k times · Source

From this page,

http://www.yiiframework.com/wiki/23/how-to-create-a-breadcrumb-widget/

It seems it suggests that we should put the files in the component folder. But if my widget contains javascript and css files, where should these files be placed?

By the way, is this a good idea that I create it as an extension? If I go this way, all widget files are more self-contained in a folder inside the extension folder. But since the widget I am going to work on is very customized, it's unlikely that it will be useful to other people or my other projects. Making it an extension seems a little bit strange.

I understand that it does not really matter where I put these files as long as the paths I am using in the codes are correct but I would like to know the common practice.

Answer

zuo picture zuo · Dec 30, 2011

I think the common practice is to put the widget in extensions folder with js & css files in an 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

extensions/
   widget_name/
     widget.class.php
     assets/
         plugin.js
         style.css