How to run applications in Yii
After installing Yii, you will have a runnable Yii application. Depending on the configuration, you can use http://hostname/basic/web/index.php or Access http://hostname/index.php. (Recommended study: yii usage tutorial)
This chapter will introduce the built-in functions of the application, how to organize the code, and how the application handles requests in general.
Information: For the sake of simplicity, throughout the "Getting Started" section, it is assumed that you have set basic/web as the root directory of the Web server and configured it. Your address to access the application will be http://hostname/index .php or similar. Please adjust the URL as needed.
Note that the project template and framework are completely different, and they are all yours after installation. You are free to add or remove code and modify everything according to your needs.
Function
An installed basic application contains four pages:
Homepage, when When you visit http://hostname/index.php, the "About" page and "Contact" page are displayed, displaying a contact form that allows end users to contact you via email, "Login" page, displays a login form used to authenticate end users. Try to log in with "admin/admin". You can see that you are currently logged in and you can "log out".
These pages use the same header and trailer. The header contains a navigation bar that allows you to switch between different pages.
You can see a toolbar at the bottom of the browser. This is a very useful debugging tool provided by Yii, which can record and display a large amount of debugging information, such as log information, response status, database queries, etc.
In addition to the web application, there is also a console script called yii, which is located in the application root directory. It can be used for background running and maintenance tasks of programs, as described in the Console Applications chapter.
Application structure
The most important directories and files in the application (assuming the application root directory is basic):
basic/ 应用根目录 composer.json Composer 配置文件, 描述包信息 config/ 包含应用配置及其它配置 console.php 控制台应用配置信息 web.php Web 应用配置信息 commands/ 包含控制台命令类 controllers/ 包含控制器类 models/ 包含模型类 runtime/ 包含 Yii 在运行时生成的文件,例如日志和缓存文件 vendor/ 包含已经安装的 Composer 包,包括 Yii 框架自身 views/ 包含视图文件 web/ Web 应用根目录,包含 Web 入口文件 assets/ 包含 Yii 发布的资源文件(javascript 和 css) index.php 应用入口文件 yii Yii 控制台命令执行脚本
Generally speaking, in the application The files can be divided into two categories: those under basic/web and those in other directories. The former can be accessed directly via HTTP (e.g. a browser), the latter cannot and should not be accessed directly.
Yii implements the Model-View-Controller (MVC) design pattern, which is also reflected in the above directory structure. The models directory contains all model classes, the 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 accessible PHP script in the entire application. The entry script accepts a web request and creates an application instance to handle it. The application parses the request with the help of its components and dispatches the request to the MVC element. Views use widgets to create complex and dynamic user interfaces.
Request life cycle
The following diagram shows how an application handles requests:
The user initiates a request to the entry script web/index.php ask.
The entry script loads the application configuration and creates an application instance to handle the request.
The application resolves the requested route through the request component.
The application creates a controller instance to handle the request.
The controller creates an action instance and executes the filter against the action.
If any filter returns failure, the action is canceled.
If all filters pass, the action will be executed.
The action loads a data model, perhaps from a database.
The action renders a view and provides the data model to it.
The rendering result is returned to the response component.
The response component sends the rendering result to the user's browser.
The above is the detailed content of How to run applications in Yii. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

As the Internet continues to develop, the demand for web application development is also getting higher and higher. For developers, developing applications requires a stable, efficient, and powerful framework, which can improve development efficiency. Yii is a leading high-performance PHP framework that provides rich features and good performance. Yii3 is the next generation version of the Yii framework, which further optimizes performance and code quality based on Yii2. In this article, we will introduce how to use Yii3 framework to develop PHP applications.

In the current information age, big data, artificial intelligence, cloud computing and other technologies have become the focus of major enterprises. Among these technologies, graphics card rendering technology, as a high-performance graphics processing technology, has received more and more attention. Graphics card rendering technology is widely used in game development, film and television special effects, engineering modeling and other fields. For developers, choosing a framework that suits their projects is a very important decision. Among current languages, PHP is a very dynamic language. Some excellent PHP frameworks such as Yii2, Ph

If you're asking "What is Yii?" check out my previous tutorial: Introduction to the Yii Framework, which reviews the benefits of Yii and outlines what's new in Yii 2.0, released in October 2014. Hmm> In this Programming with Yii2 series, I will guide readers in using the Yii2PHP framework. In today's tutorial, I will share with you how to leverage Yii's console functionality to run cron jobs. In the past, I've used wget - a web-accessible URL - in a cron job to run my background tasks. This raises security concerns and has some performance issues. While I discussed some ways to mitigate the risk in our Security for Startup series, I had hoped to transition to console-driven commands

In modern software development, building a powerful content management system (CMS) is not an easy task. Not only do developers need to have extensive skills and experience, but they also need to use the most advanced technologies and tools to optimize their functionality and performance. This article introduces how to use Yii2 and GrapeJS, two popular open source software, to implement back-end CMS and front-end visual editing. Yii2 is a popular PHPWeb framework that provides rich tools and components to quickly build

With the rapid development of the Internet, APIs have become an important way to exchange data between various applications. Therefore, it has become increasingly important to develop an API framework that is easy to maintain, efficient, and stable. When choosing an API framework, Yii2 and Symfony are two popular choices among developers. So, which one is more suitable for API development? This article will compare these two frameworks and give some conclusions. 1. Basic introduction Yii2 and Symfony are mature PHP frameworks with corresponding extensions that can be used to develop
