If you plan to reuse functionality, it is recommended to provide the code in composer packages. Luckily, Yii 2.0 Framework is equipped with a code generator for creating ready to use extension skeletons in a minute.
> Note! Code generation is only available with `YII_ENV_DEV=true`.
Building an extension
---------------------
### Gii from the command line (recommended)
### Generating skeleton with Gii
To create an extension from the command line adjust the parameters in the following command and run it from your
project root.
```
./yii gii/extension \
--vendorName=you \
--packageName=yii2-new-module \
--namespace=you\\new\\ \
--vendorName=mycompany \
--packageName=yii2-mypackage \
--namespace=mycompany\\mypackage\\ \
--license=BSD-3-Clause \
--title="A new Yii 2.0 module" \
--description="Enter some useful text here..." \
--title="Extension for Yii 2.0 Framework" \
--description="Provides cool stuff" \
--authorName="Your Name" \
--authorEmail=you@example.com
--authorEmail=you@yourdomain.com
```
### Gii Web interface
This will generate a folder in `runtime/tmp-extensions/yii2-mypackage` with example code for the extension.
- Open `Gii > Extension Generator`
- Enter values
- Click preview
- Click generate
- Follow instructions and push repo to GitHub
- Require via `composer`
- Happy coding...
### Make your extension available via composer
### Share your extension
Create a new private or public repository, eg. on [GitHub](https://github.com/new).
Create a new private or public repository, eg. on [GitHub](https://github.com/new)
Then, go to the folder with the generated code inside your project's `runtime` folder and initializie a temporary
Git repository
```
cd runtime/tmp-extensions/yii2-new-module
cd runtime/tmp-extensions/yii2-mypackage
git init
git add -A
git add .
```
Check if you have added the correct files with
```
git status
```
It should show three files to be committed. If everything is fine commit and push your changes to your repo.