How to create extensions?

I am a yii2 developer working actively in many projects.
Now, I am interested in creating extensions for yii2 so that other people can use too.

Anyone can help me to start with an example.

Let’s say: I want to create an extension for full calendar.

How to start this?

1 Like

Hi Patrik,

Yeah it’s a good idea to create an extension and share it with others.

Please take a look at the following section of the guide, and you’ll get some idea what it’s like to create an Yii 2 extension. I believe that it should be enough for you to start making your own extension. And if you have any further question on the way, you can ask for help in this community.

Guide > Application Structure > Extensions
https://www.yiiframework.com/doc/guide/2.0/en/structure-extensions

2 Likes

I used the gii.

I have generated the tmp-extensions to the runtime folder using gii and pushed the code to the github (https://github.com/karmakarpatrick/fullcalendar.git)

Then added the :slight_smile:

"repositories":[    
{ 
"type": "git", 
"url": "https://github.com/karmakarpatrick/fullcalendar.git"  

}
]

Now, when i follow the below steps, I get this error:

Please Help!!!

Hi Community,

Tank You!!! I did a mistake and it is resolved now.
Thank You

1 Like

then last submit your extension to http://packagist.org/. It will help you to install packages in fast and reliable

1 Like

I am able to create the extension and submit it to the github and the download it using composer.
Thats the first step, i did it and it was successful.
Now, I want to modify that extension.
I have a js file as an asset and and view where the details reside.
Now how to integrate all this.

Lets say: I tested by creating an file which will wrap the mathjs library.
The following things have been integrated:
in app\assets:
MathAsset -> to include the files.
In Site Controller: Used Index action to redirect to the view
In views/site: index.php where the interface is there.

Now how integrate it into the extension

Can you show us your github repo of this extension?

Here there is nothing. Just the code generated using the Gii.

I have the code locally.

Ah, OK.

I think that you are not ready to create an extension yet.

Before trying to create an extension, try creating a reusable Widget or component that provides the math notepad functionality.

’Reusable’ is the keyword. You seems to try to include the index action of the site controller into your math notepad extension, but you should not do it. Your math notepad must be usable in any other project. So you have to divide the code in your index action and index view into 2 parts: one that belongs to the widget and the other that belongs to the current project. And then make a Widget or component from the former, and use it in your current project. Then the Widget or component can easily be used in other projects. And then, only then, you are ready to create an extension.

2 Likes

Thank You!! Samdark that you are helping me actively.

If you help me in integrating any extension by example(lets say the Math JS javascript), please provide video of making any extensions
. i am eager to make extensions for yii2.

Sorry, but I’m quite sure that @samdark won’t be able to make such a video because he’s quite busy developing Yii 3. And also I(@softark) have no interest at all in making any video.

I understand that examples and videos may help us very much, but they are not that easy to make (at least for me). They consume your time and energy quite a lot.

1 Like

@softark No issues. I will try and still if i get any problem, will ask you.

1 Like