Various Yii 3.0 related documentation
After installing Yii, you have a working Yii application. This section introduces the application’s built-in functionality, how the code is organized, and how the application handles requests in general.
Note that unlike the framework itself, after you install a project template, it’s all yours. You’re free to add or delete code and overall change it as you need.
The installed application has only the homepage, which displays when you access the URL http://localhost/
.
It shares a common layout that you can reuse on further pages.
In addition to the web application, you can access a console script via APP_ENV=dev ./yii
or, in case of Docker, make yii
.
Use this script to run background and maintenance tasks for the application, which the
Console Application Section describes.
The most important directories and files in your application are (assuming the application’s root directory is app
):
assets/ Application assets to be published.
config/ Configuration.
common/ Configs applied to both console and web.
di/ DI container configuration.
aliasess.php Aliases.
application.php Application configuration.
bootstrap.php Bootstrap configuration.
params.php Various parameters used in DI configs.
routes.php Application routes.
console/ Configs applied to console.
commands.php Registered console commands.
params.php Various parameters used in DI configs.
web/ Configs applied to web.
di/ DI container configuration.
params.php Various parameters used in DI configs.
environments/ Environment-based configs.
dev/ Configs applied in dev environment.
params.php Various parameters used in DI configs.
prod/ Configs applied in prod environment.
params.php Various parameters used in DI configs.
test/ Configs applied in test environment.
params.php Various parameters used in DI configs.
configuration.php Defines how to read application configs.
.merge-plan.php Merge plan to assemble configs according to. Build using `configuration.php`.
docker/ Docker configuration.
dev/ Dev environment.
.env Environment variables.
compose.yml Services for dev environment.
prod/ Prod environment.
.env Environment variables.
compose.yml Services for prod environment.
test/ Test environment.
.env Environment variables.
compose.yml Services for test environment.
.env Common environment variables.
compose.yml Common services.
Dockerfile Images to use.
public/ Files publically accessible from the Internet.
assets/ Published assets.
index.php Entry script for web.
runtime/ Files generated during runtime.
src/ Application source code.
Command/ Console commands.
Controller/ Controllers.
Handler/ Custom handler for 404.
Layout/ Layouts.
autoload.php Autoloader.
Environment.php Environment helper.
tests/ A set of Codeception tests for the application.
vendor/ Installed Composer packages.
.gitignore Files and directories to be ignored by Git.
.php-cs-fixer.php PHP Coding Standards Fixer configuration.
c3.php Codeception code coverage script.
condeception.yml Codeception configuration.
composer.json Composer configuration.
composer.lock Composer lock file.
Makefile Makefile with shortcut commands.
psalm.xml Psalm configuration.
rector.php Rector configuration.
yii Console application entry point.
In general, the files in the application fall into two groups: those under app/public
and those
under other directories. You can access the former directly via HTTP (i.e., in a browser), while you shouldn’t expose the latter.
Each application has an entry script public/index.php
, the only web-accessible PHP script in the application.
The entry script uses an application runner to create an instance of
an incoming request with the help of one of PSR-7 packages and passes it to an application
instance. The application executes a set of middleware sequentially to process the request.
It then passes the result to the emitter, which sends the response to the browser.
Depending on the middleware you use, the application may behave differently. By default, a router uses the requested URL and configuration to choose a handler and execute it to produce a response.
You can learn more about the application template from the yiisoft/app package documentation.
The following diagram shows how an application handles a request.
public/index.php
.[!NOTE] ← Creating a project | Saying hello →