Commit 66b141d8 by Qiang Xue

guide wip [skip ci]

parent e2f6a555
......@@ -70,16 +70,17 @@ Verifying Installation
----------------------
After installation, you can use your browser to access the installed Yii application with the following URL,
assuming you have installed Yii in a directory named `basic` that is under the document root of your Web server,
assuming you have installed Yii in a directory named `basic` that is under the document root of your Web server
and the server name is `hostname`,
```
http://localhost/basic/web/index.php
http://hostname/basic/web/index.php
```
You should see a "Congratulations!" page in your browser. If not, please check if your PHP installation satisfies
Yii's requirements by using one of the following approaches:
* Use a browser to access the URL `http://localhost/basic/requirements.php`
* Use a browser to access the URL `http://hostname/basic/requirements.php`
* Run the following commands:
```
......@@ -105,17 +106,14 @@ an [Apache HTTP server](http://httpd.apache.org/) or an [Nginx HTTP server](http
either Windows or Linux.
On a production server, you may want to configure your Web server so that the application can be accessed
via the URL `http://hostname` without the part `/basic/web/index.php`. This requires configuring your
Web server by
* pointing the Web document root to the `basic/web` folder;
* and hiding `index.php` from the URL.
By setting `basic/web` as the document root, you also secure your application by preventing end users
from accessing your private application code and sensitive data files that are stored in the sibling directories
of `basic/web`.
Below we show the configurations recommended for Apache and Nginx.
via the URL `http://hostname/index.php` instead of `http://hostname/basic/web/index.php`. This
requires pointing the document root of your Web server to the `basic/web` folder. And you may also
want to hide `index.php` from the URL, as described in the [URL Parsing and Generation](runtime-url-handling.md) section.
In this subsection, we will show how to configure your Apache or Nginx server to achieve these goals.
> Info: By setting `basic/web` as the document root, you also prevent end users from accessing
your private application code and sensitive data files that are stored in the sibling directories
of `basic/web`. This makes your application more secure.
> Info: If your application will run in a shared hosting environment where you do not have the permission
to modify its Web server setting, you may adjust the structure of your application. Please refer to
......
Running Applications
====================
Application Structure
---------------------
You now have a working Yii application which can be accessed via URL `http://hostname/index.php`.
In this section, we will introduce what functionalities this application has, how the code is organized,
and how the application handles requests in general.
The basic application that you just installed is organized as follows,
```
basic/ application base path
assets/ contains asset bundles
commands/ contains console commands
config/ contains application configurations
controllers/ contains controller classes
mail/ contains views for mail messages
layouts/ contains layouts for mail messages
models/ contains model classes
runtime/ contains files generated during runtime, such as logs, cache files
views/ application view base path
layouts/ contains layout files
site/ contains view files for the site controller
web/ application Web root
assets/ contains published asset files by Yii, such as css files, js files
css/ contains CSS files
```
> Info: For simplicity, throughout this "Getting Started" tutorial we assume that you have set `basic/web`
as the document root of your Web server. If you have not done so, the URL for accessing
your application could be `http://hostname/basic/web/index.php`, or something similar.
Please adjust the URLs accordingly in our descriptions.
The basic application template includes four pages: a homepage, an about page, a contact page, and a login page.
The contact page displays a contact form that users can fill in to submit their inquiries to the webmaster. Assuming the site has access to a mail server and that the administrator's email address is entered in the configuration file, the contact form will work. The same goes for the login page, which allows users to be authenticated before accessing privileged content.
Functionalities
---------------
Root directory contains a set of files.
The application that you have installed has four pages:
- `.gitignore` contains a list of directories ignored by git version system. If you need something never get to your source
code repository, add it there.
- `codeception.yml` - Codeception config.
- `composer.json` - Composer config described in detail below.
- `LICENSE.md` - license info. Put your project license there. Especially when opensourcing.
- `README.md` - basic info about installing template. Consider replacing it with information about your project and its
installation.
- `requirements.php` - Yii requirements checker.
- `yii` - console application bootstrap.
- `yii.bat` - same for Windows.
* the homepage is the page displayed when you access the URL `http://hostname/index.php`;
* the "About" page;
* the "Contact" page displays a contact form that allows end users to contact you by filling out the form;
* the "Login" page displays a login form that can be used to authenticate end users. Try logging in
with "admin/admin", and you will find the "Login" main menu item will change to "Logout".
These pages share a common header and footer. The header contains a main menu bar to allow navigate
among different pages.
### config
You should also see a toolbar sticking at the bottom of the browser window when it displays any of the above pages.
This is a useful [debugger tool](tool-debugger.md) provided by Yii to help you check various debugging information
about the application execution, such as log messages, response status, database queries, and so on.
This directory contains configuration files:
- `console.php` - console application configuration.
- `params.php` - common application parameters.
- `web.php` - web application configuration.
- `web-test.php` - web application configuration used when running functional tests.
All these files are returning arrays used to configure corresponding application properties. Check
[Configuration](configuration.md) guide section for details.
### views
Application Structure
---------------------
Views directory contains templates your application is using. In the basic template there are:
The following is a list of the most important directories and files in your application,
```
layouts
main.php
site
about.php
contact.php
error.php
index.php
login.php
basic/ application base path
composer.json used by Composer, describes package information
config/ contains application and other configurations
console.php the console application configuration
web.php the Web application configuration
commands/ contains console command classes
controllers/ contains controller classes
models/ contains model classes
runtime/ contains files generated by Yii during runtime, such as logs, cache files
vendor/ contains the installed Composer packages, including the Yii framework
views/ contains view files
web/ application Web root, contains Web accessible files
assets/ contains published asset files (js, css) by Yii
index.php the entry script of the application
yii the Yii console command execution script
```
`layouts` contains HTML layouts i.e. page markup except content: doctype, head section, main menu, footer etc.
The rest are typically controller views. By convention these are located in subdirectories matching controller id. For
`SiteController` views are under `site`. Names of the views themselves are typically match controller action names.
Partials are often named starting with underscore.
In general, the files in the application can be divided into two parts: those under `basic/web` and those
under other directories. The former can be directly accessed from Web, while the latter can/should not.
### web
Your application uses a single entry `web/index.php`. It is the only PHP script that is directly accessible from Web.
It takes ALL Web requests, creates an [application](structure-applications.md) instance to handle the requests,
and then sends back the responses.
Directory is a webroot. Typically a webserver is pointed into it.
Yii implements the [model-view-controller (MVC)](http://wikipedia.org/wiki/Model-view-controller) design pattern,
as reflected in the above directory organization. The `models` directory contains all [model classes](structure-models.md),
the `views` directory contains all [view scripts](structure-views.md), and the `controllers` directory contains
all [controller classes](structure-controllers.md).
```
assets
css
index.php
index-test.php
```
The following diagram shows the static structure of an application:
`assets` contains published asset files such as CSS, JavaScript etc. Publishing process is automatic so you don't need
to do anything with this directory other than making sure Yii has enough permissions to write to it.
`css` contains plain CSS files and is useful for global CSS that isn't going to be compressed or merged by assets manager.
![Static structure of Yii application](images/structure.png)
`index.php` is the main web application bootstrap and is the central entry point for it. `index-test.php` is the entry
point for functional testing.
Request Lifecycle
-----------------
The following diagram shows a typical workflow of a Yii application handling a user request:
......@@ -117,26 +96,3 @@ The following diagram shows a typical workflow of a Yii application handling a
10. The view rendering result--the output from the previous steps--is embedded within a [layout](view.md#layout) to create a complete HTML page.
11. The action completes the view rendering and displays the result to the user.
Application Structure
-----
> Note: This section is under development.
Yii implements the model-view-controller (MVC) design pattern, which is
widely adopted in Web and other application programming. MVC aims to separate business logic from
user interface considerations, allowing developers to more easily change one component of an application without affecting, or even touching, another.
In MVC, the *model* represents both the
information (the data) and the business rules to which the data must adhere. The *view* contains elements
of the user interface, such as text, images, and form elements. The *controller* manages
the communication between the model and the view, acting as an agent that handles actions and requests.
Besides implementing the MVC design pattern, Yii also introduces a *front-controller*, called
*application*. The front-controller encapsulates the *execution context* for the processing of a request. This means that the front-controller collects information about a user request, and
then dispatches it to an appropriate controller for the actual handling of that request. In other words, the front-controller is the primary application manager, handling all requests and delegating action accordingly.
The following diagram shows the static structure of a Yii application:
![Static structure of Yii application](images/structure.png)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment