In this article we will talk about the Yii Framework, a framework that we have used for developing full stack applications in several of our web projects implemented in PHP.
One of the main reasons for choosing Yii is its very low learning curve compared to other frameworks. This makes it easy for developers to adopt and use, allowing applications to be deployed quickly and efficiently. In addition, it does not have high requirements for installation on web servers, which makes it very easy to get up and running.
What is Yii?
Yii is a powerful, component-based PHP framework that was developed for the development of extensive web applications. It enables a high level of code reuse and significantly speeds up the development process.
The Yii project was launched on 1 January 2008 with the aim of solving some of the problems of the PRADO framework. For example, PRADO is characterised by the fact that it can only process complex pages slowly, has a steep learning curve and has several control elements that make customisation difficult. In contrast, Yii is much simpler and more efficient. In October 2008, after 10 months of private work, the first alpha version of Yii was released. On 3 December of the same year, Yii 1.0 was formally launched.
Versions of Yii
There are currently two major versions of Yii: version 1.1 and version 2.0. Version 1.1, which belongs to the previous generation, is currently only offered as maintenance. Version 2.0 has been completely rewritten and incorporates the latest technologies and protocols, including Composer, PSR, Namespaces, Traits and others. Version 2.0 represents the current generation of the framework, and its further development will be focussed on in the coming years. This guide is mainly based on version 2.0 of the framework
Yii 1.1
1. requirements
To run an application developed with Yii, a web server that supports PHP version 5.1.0 or higher is required. In addition, it is advantageous for developers who want to work with Yii to have knowledge of object-orientated programming (OOP), as this framework is based entirely on this paradigm.
2. What is Yii recommended for?
Yii is a generic web development framework suitable for creating any type of web application. Its low resource consumption and advanced caching features make it ideal for high-traffic applications such as web portals, forums, content management systems (CMS), e-commerce platforms and others.
3. How does Yii compare to other frameworks?
Yii, like other PHP frameworks, follows the MVC (Model-View-Controller) design pattern. It is characterised by its high efficiency, a wide range of functions and excellent documentation. From the beginning, it was designed specifically for web application development, unlike other frameworks that are by-products of other projects or integrate multiple third-party components. Yii is the result of its creators’ extensive experience in web development and a thorough analysis of the most popular frameworks on the market.
Model-View-Controller (MVC)
Yii uses the Model-View-Controller (MVC) design pattern widely used in web development. This pattern aims to separate the business logic from the user interface aspects so that developers can change each of these parts independently without one affecting the other. In the MVC pattern, the model represents the data and business rules, the view manages the UI elements such as text and forms, while the controller is responsible for managing the interaction between the model and the view.
In addition to MVC, Yii introduces a front controller called ‘application’, which represents the execution context of request processing. The application is responsible for receiving user requests and forwarding them to the appropriate controller for processing
The following diagram illustrates the static structure of a Yii application:

Static Yii application structure
A typical task flow
The following diagram shows a typical task flow of a Yii application when solving a user request:

- A user makes a request with the following URL: http://www.example.com/index.php?r=post/show&id=1, and the web server processes the request by executing the start script in index.php.
- The login script creates an instance of the application and executes it.
- The application receives the detailed information about the user’s request from the request component.
- The controller determines the controller and the required action with the help of the application component urlManager. In this example, the controller is post, which refers to the PostController class, and the action is show, whose meaning is determined by the controller.
- The application creates an instance of the requested controller to resolve the user’s request. The controller determines that the show action refers to the actionShow method in the controller class. It then creates the filters associated with this action (e.g. access control, benchmarking) and executes them. The action is executed if the filters allow it.
- The action reads the post model whose ID is 1 from the database.
- The action executes the view named show with the post model.
- The view reads and displays the attributes of the post model.
- The view executes some widgets.
- The rendered result is inserted into a layout.
- The action completes the rendered view and displays it to the user.
Yii 2
Version 2.0 has been completely rewritten and incorporates the latest technologies and protocols, including Composer, PSR, Namespaces, Traits and others. Version 2.0 represents the current generation of the framework.
Model-View-Controller (MVC)
Yii implements the Model-View-Controller (MVC) design pattern, which is reflected in the directory structure used. The models directory contains all model classes, the views directory contains all views (templates) and the controllers directory contains all controller classes.
The following diagram shows the static structure of an application.

Each application has a web/index.php gateway script, the only PHP script that is accessible over the Internet. The inbound script receives an incoming request and creates an instance of an application to process it. The application resolves the request using its components and sends it to the other MVC elements. Widgets are used in views to support the construction of complex and dynamic interface elements.
Life cycle of a request
The following diagram shows how an application processes a request:

- A user makes a request to the input script web/index.php.
- The input script loads the application configuration and creates an instance of the application to process the request.
- The application resolves the requested path using the application’s request component.
- The application creates an instance of a controller to process the request.
- The controller creates an instance of an action and executes the filters of the action.
- If one of the filters fails, the action is cancelled.
- If all filters are successful, the action is executed.
- The action loads data from the model, possibly from the database.
- The action renders a view and passes the loaded model data to it.
- The result of the rendering is passed to the response component of the application.
- The response component sends the rendering result to the user’s browser.
Yii in our company
At WATA Factory, we developed an application with Yii 1.1 a few years ago because we needed a PHP framework that could be developed very quickly. We also use Limesurvey as our survey engine, which is based on Yii.