Category: Yii

  • Using Controllers

    Controllers in web applications should extend from yii\web\Controller or its child classes. In console applications, they should extend from yii\console\Controller or its child classes. Let us create an example controller in the controllers folder. Step 1 − Inside the Controllers folder, create a file called ExampleController.php with the following code. Step 2 − Create an example view in the views/example folder. Inside that folder, create a file…

  • Controllers

    Controllers are responsible for processing requests and generating responses. After user’s request, the controller will analyze request data, pass them to model, then insert the model result into a view, and generate a response. Understanding Actions Controllers include actions. They are the basic units that user can request for execution. A controller can have one…

  • Entry Scripts

    Entry scripts are responsible for starting a request handling cycle. They are just PHP scripts accessible by users. The following illustration shows the structure of an application − Web application (as well as console application) has a single entry script. The End user makes request to the entry script. Then the entry script instantiates application…

  • Application Structure

    There is only one folder in the overall code base that is publicly available for the web server. It is the web directory. Other folders outside the web root directory are out of reach for the web server. Note − All project dependencies are located in the composer.json file. Yii2 has a few important packages that are already…

  • Create Page

    Now we are going to create a “Hello world” page in your application. To create a page, we must create an action and a view. Actions are declared in controllers. The end user will receive the execution result of an action. Step 1 − Declare the speak action in the existing SiteController, which is defined in the class file…

  • Installation

    The most straightforward way to get started with Yii2 is to use the basic application template provided by the Yii2 team. This template is also available through the Composer tool. Step 1 − Find a suitable directory in your hard drive and download the Composer PHAR (PHP archive) via the following command. Step 2 − Then move…

  • Overview

    The Yii[ji:] framework is an open-source PHP framework for rapidly-developing, modern Web applications. It is built around the Model-View-Controller composite pattern. Yii provides secure and professional features to create robust projects rapidly. The Yii framework has a component-based architecture and a full solid caching support. Therefore, it is suitable for building all kinds of Web applications: forums,…