tutorial-start-from-scratch.md 2.75 KB
Newer Older
1 2 3
Creating your own Application structure
=======================================

4
> Note: This section is under development.
Qiang Xue committed
5

Larry Ullman committed
6 7
While the [basic](apps-basic.md) and [advanced](apps-advanced.md) application templates are great for most of your needs,
you may want to create your own application template with which to start your projects.
8

Larry Ullman committed
9
Application templates in Yii are simply repositories containing a `composer.json` file, and registered as a Composer package. Any repository can be identified as a Composer package, making it installable via `create-project` Composer command.
10

Larry Ullman committed
11 12
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 templates
as a base. Let's use the basic template here.
13

Larry Ullman committed
14
Clone the Basic Template
15 16
----------------------------------------

Larry Ullman committed
17 18 19
The first step is to clone the basic Yii template's Git repository:

```bash
20 21 22
git clone git@github.com:yiisoft/yii2-app-basic.git
```

Larry Ullman committed
23 24
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
of its contents from the download.
25

Larry Ullman committed
26
Modify the Files
27 28
------------

Larry Ullman committed
29 30
Next, you'll want to modify the `composer.json` to reflect your template. Change the `name`, `description`, `keywords`, `homepage`, `license`, and `support` values
to describe your new template. Also adjust the `require`, `require-dev`, `suggest`, and other options to match your template's requirements.
31

Larry Ullman committed
32 33
> Note: In the `composer.json` file, use the `writable` parameter under `extra` to specify
> per file permissions to be set after an application is created using the template.
34

Larry Ullman committed
35
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.
36

Larry Ullman committed
37
Make a Package
38 39
--------------

Larry Ullman committed
40
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://githumb.com) is the best place to host it. If you intend to keep your template non-collaborative, any Git repository site will do.
41

Larry Ullman committed
42 43
Next, you need to register your package for Composer's sake. For public templates, the package should be registered at [Packagist](https://packagist.org/).
For private templates, it is a bit more tricky to register the packge. For instructions, see the [Composer documentation](https://getcomposer.org/doc/05-repositories.md#hosting-your-own).
44

Larry Ullman committed
45
Use the Template
46 47
------

Larry Ullman committed
48
That's all that's required to create a new Yii application template. Now you can create projects using your template:
49 50

```
51 52
composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
composer create-project --prefer-dist --stability=dev mysoft/yii2-app-coolone new-project
53
```