bootstrap.md 2.86 KB
Newer Older
Qiang Xue committed
1 2 3
Bootstrap with Yii
==================

Qiang Xue committed
4 5 6 7 8 9 10 11 12 13
Yii provides a few read-to-use application templates. Based on your needs, you may
choose one of them to bootstrap your project.

In following, we describe how to get started with the "Yii 2 Basic Application Template".


### Install via Composer

If you do not have [Composer](http://getcomposer.org/), you may download it from
[http://getcomposer.org/](http://getcomposer.org/) or run the following command on Linux/Unix/MacOS:
Qiang Xue committed
14 15

~~~
Qiang Xue committed
16
curl -s http://getcomposer.org/installer | php
Qiang Xue committed
17 18
~~~

Qiang Xue committed
19 20 21 22 23 24 25 26 27
You can then install the Bootstrap Application using the following command:

~~~
php composer.phar create-project --stability=dev yiisoft/yii2-app-basic yii-basic
~~~

Now you should be able to access the Bootstrap Application using the URL `http://localhost/yii-basic/www/`,
assuming `yii-basic` is directly under the document root of your Web server.

Qiang Xue committed
28 29 30 31 32 33 34 35 36 37

As you can see, the application has four pages: the homepage, the about page,
the contact page and the login page. The contact page displays a contact
form that users can fill in to submit their inquiries to the webmaster,
and the login page allows users to be authenticated before accessing privileged contents.


The following diagram shows the directory structure of this application.

~~~
Qiang Xue committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
yii-basic/
   yii                    yii command line script for Unix/Linux
   yii.bat                yii command line script for Windows
   requirements.php       the requirement checker script
   commands/              containing customized yii console commands
   config/                containing configuration files
      console.php         the console application configuration
      main.php            the Web application configuration
   controllers/           containing controller class files
      SiteController.php  the default controller class
   vendor/                containing third-party extensions and libraries
   models/                containing model class files
      User.php            the User model
      LoginForm.php       the form model for 'login' action
      ContactForm.php     the form model for 'contact' action
   runtime/               containing temporarily generated files
   views/                 containing controller view and layout files
      layouts/            containing layout view files
         main.php         the base layout shared by all pages
      site/               containing view files for the 'site' controller
         about.php        the view for the 'about' action
         contact.php      the view for the 'contact' action
         index.php        the view for the 'index' action
         login.php        the view for the 'login' action
   www/                   containing Web-accessible resources
     index.php            Web application entry script file
     assets/              containing published resource files
     css/                 containing CSS files
Qiang Xue committed
66 67 68
~~~


69
TBD