[yii2] How to create new extensions locally without version or Git controls

Table of Contents

Using Git in building extensions is great. When using Git, you must load the extension through Composer. Likewise when updating or correcting errors that occur.

Of course, this will be troublesome, when the extension made is still in the development stage. To avoid this, we can use composers locally without version or Git controls. So that every code change made can immediately function without the need to update and commit changes through composer or git.

Here are the steps to do so:

1. Generate Extension via Gii

The first thing you should and do is create an extension template from gii, you can open“http://hostname/index.php?r=gii”. Then select“Extension Generator”.

After that complete the form filling in accordance with the extension you created. The most important thing in the filling is the “output path”, you can fill it with “@vendor\bardimin” if you create an extension in the vendor directory\bardimin.

TOP TUTORIALS:  Create real-time applications with Nodes.js

After that select “Generate” to create the extension files. Next, go to the directory “vendor\bardimin\yii2-myextension” if you fill out the form above like an example. Formed 3 files under the name AutoloadExample.php, composer.json, and README.md.

2. Edit Composer.json

Then open the composer.json file from the extension that has been created earlier and add

"minimum-stability": "dev",

3. Edit Yii2 Composer.json

After that, go back to the yii2 installation directory root and open the composer.json file.

Then add “bardimin/yii2-myextension”: “@dev” to“require-dev”and to“repositories”point to the directory where the extension was created earlier, for example “C:\xampp\htdocs\yii2-advanced\vendor\bardimin\yii2-myextension”.

{
	..............
	..............
	..............
	
    "require-dev": {
        ..............
		..............
		..............
        "bardimin/yii2-myextension": "@dev"
    },
	
	..............
	..............
	
    "repositories": [
        ..............
        ..............
		..............
        {
            "type": "path",
            "url": "C:\\xampp\\htdocs\\yii2-advanced\\vendor\\bardimin\\yii2-myextension"
        }
    ]
}

4. Composer update

After all the composer updates through cmd with

composer update

If all is right, you’ll see Composers load your library and perform on your terminal.

Leave a Comment

Your email address will not be published. Required fields are marked *