|
| 1 | +Creating your own Application structure |
| 2 | +======================================= |
| 3 | + |
| 4 | +> Note: This section is under development. |
| 5 | +
|
| 6 | +While the [basic](https://github.com/yiisoft/yii2-app-basic) and [advanced](https://github.com/yiisoft/yii2-app-advanced) |
| 7 | +project templates are great for most of your needs, you may want to create your own project template with which |
| 8 | +to start your projects. |
| 9 | + |
| 10 | +Project templates in Yii are simply repositories containing a `composer.json` file, and registered as a Composer package. |
| 11 | +Any repository can be identified as a Composer package, making it installable via `create-project` Composer command. |
| 12 | + |
| 13 | +Since it's a bit too much to start building your entire template from scratch, it is better to use one of the built-in |
| 14 | +templates as a base. Let's use the basic template here. |
| 15 | + |
| 16 | +Clone the Basic Template |
| 17 | +---------------------------------------- |
| 18 | + |
| 19 | +The first step is to clone the basic Yii template's Git repository: |
| 20 | + |
| 21 | +```bash |
| 22 | +git clone git@github.com:yiisoft/yii2-app-basic.git |
| 23 | +``` |
| 24 | + |
| 25 | +Then wait for the repository to be downloaded to your computer. Since the changes made to the template won't be pushed back, you can delete the `.git` diretory and all |
| 26 | +of its contents from the download. |
| 27 | + |
| 28 | +Modify the Files |
| 29 | +------------ |
| 30 | + |
| 31 | +Next, you'll want to modify the `composer.json` to reflect your template. Change the `name`, `description`, `keywords`, `homepage`, `license`, and `support` values |
| 32 | +to describe your new template. Also adjust the `require`, `require-dev`, `suggest`, and other options to match your template's requirements. |
| 33 | + |
| 34 | +> Note: In the `composer.json` file, use the `writable` parameter under `extra` to specify |
| 35 | +> per file permissions to be set after an application is created using the template. |
| 36 | +
|
| 37 | +Next, actually modify the structure and contents of the application as you would like the default to be. Finally, update the README file to be applicable to your template. |
| 38 | + |
| 39 | +Make a Package |
| 40 | +-------------- |
| 41 | + |
| 42 | +With the template defined, create a Git repository from it, and push your files there. If you're going to open source your template, [Github](http://github.com) is the best place to host it. If you intend to keep your template non-collaborative, any Git repository site will do. |
| 43 | + |
| 44 | +Next, you need to register your package for Composer's sake. For public templates, the package should be registered at [Packagist](https://packagist.org/). |
| 45 | +For private templates, it is a bit more tricky to register the package. For instructions, see the [Composer documentation](https://getcomposer.org/doc/05-repositories.md#hosting-your-own). |
| 46 | + |
| 47 | +Use the Template |
| 48 | +------ |
| 49 | + |
| 50 | +That's all that's required to create a new Yii project template. Now you can create projects using your template: |
| 51 | + |
| 52 | +``` |
| 53 | +composer global require "fxp/composer-asset-plugin:~1.0.0" |
| 54 | +composer create-project --prefer-dist --stability=dev mysoft/yii2-app-coolone new-project |
| 55 | +``` |
0 commit comments