Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 704
bobo Avatar asked Dec 30 '11 11:12

bobo


People also ask

How to create a widget in yii2?

Create Your Own Widget In Yii2.0. First create a folder named "components" in the project root directory. Now create one class 'HelloWidget' inside the components folder. Using this widget, we will show the welcome message with user name. Please see the below code to create a widget class.

How to create a custom widget in Jira?

Here are the simple steps for creating a custom widget. Step1: Make a folder named “components” in your project root folder. step2: Create a file with desired widget name inside components folder and copy paste the below code and change the class name in the code.

How to show welcome message with user name in Yii?

Override the yii\base\Widget::init () and/or yii\base\Widget::run () methods. Note: In yii 1.x, we will use component folder. First create a folder named "components" in the project root directory. Now create one class 'HelloWidget' inside the components folder. Using this widget, we will show the welcome message with user name.

How to create a custom widget in WordPress?

Here are the simple steps for creating a custom widget. Make a folder named “components” in your project root folder. Create a file with desired widget name inside components folder and copy paste the below code and change the class name in the code. Example – Mywidget.php


1 Answers

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
like image 103
zuo Avatar answered Oct 01 '22 10:10

zuo