After installing Yii, you have a working Yii application that can be accessed via
upon your configuration. This section will introduce the application's built-in functionality,
how the code is organized, and how the application handles requests in general.
Info: For simplicity, throughout this "Getting Started" tutorial, it's assumed that you have set
basic/webas the document root of your Web server, and configured the URL for accessing your application to be
https://hostname/index.phpor something similar. For your needs, please adjust the URLs in our descriptions accordingly.
Note that unlike framework itself, after project template is installed it's all yours. You're free to add or delete code and overall modify it as you need.
The basic application installed contains four pages:
These pages share a common header and footer. The header contains a main menu bar to allow navigation among different pages.
You should also see a toolbar at the bottom of the browser window. This is a useful debugger tool provided by Yii to record and display a lot of debugging information, such as log messages, response statuses, the database queries run, and so on.
Additionally to the web application, there is a console script called
yii, which is located in the applications base directory.
This script can be used to run background and maintenance tasks for the application, which are described
in the Console Application Section.
The most important directories and files in your application are (assuming the application's root directory is
In general, the files in the application can be divided into two types: those under
basic/web and those
under other directories. The former can be directly accessed via HTTP (i.e., in a browser), while the latter can not and should not be.
Yii implements the model-view-controller (MVC) architectural pattern,
which is reflected in the above directory organization. The
models directory contains all model classes,
views directory contains all view scripts, and the
controllers directory contains
all controller classes.
The following diagram shows the static structure of an application.
Each application has an entry script
web/index.php which is the only Web accessible PHP script in the application.
The entry script takes an incoming request and creates an application instance to handle it.
The application resolves the request with the help of its components,
and dispatches the request to the MVC elements. Widgets are used in the views
to help build complex and dynamic user interface elements.
The following diagram shows how an application handles a request.
Found a typo or you think this page needs improvement?
Edit it on github !