[yii2] Comment créer de nouvelles extensions sans contrôle de version ou de Git ?

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 ».

gii extension 01

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 « @vendorbardimin » if you create an extension in the vendor directorybardimin.

gii extension 02

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

gii extension 03

2. Edit Composer.json

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

"minimum-stability": "dev",
composer 01 1

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
composer 02

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

ARTICLES LIÉS

Dernières articles