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.
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With