Question

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.

Was it helpful?

Solution

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

OTHER TIPS

I would join the recommendation to put the widget under /protected/extensions. I put the assets in a slightly more detailed manner: /protected/extensions/WidgetClassName/assets/ and the widget view files in /protected/extensions/WidgetClassName/views/...

Don't forget to edit your /protected/config/main.php and add a row in the 'import' section (for autoloading of the widget): 'ext.WidgetClassName.WidgetClassName.*'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top