Yii 2 Interview Questions & Answers

Yii 2 Interview Questions

Looking for a career in Yii 2? The Yii 2 is known as a framework which is an open-source PHP framework built to develop latest web applications. It is developed across the Model-View-Controller composite method. It is useful for building different types of web applications: forums, portals, content managements systems, RESTful services, e-commerce websites etc. If you are expertise on above functions you will be eligible to apply for many jobs posted by top recruiters. If you have key skills such as Yii2, Laravel, MVC, JSON, SQ and expertise in Html5, CSS, php, javascript, Yii2, Laravel, MVC design then search and apply for various jobs posted on wisdom jobs. Yii 2.0 is an advanced version of Yii framework. Following Yii 2 job interview questions and answers page for more information.

Yii 2 Interview Questions And Answers

Yii 2 Interview Questions
    1. Question 1. What Is Yii 2 ? Please Explain?

      Answer :

      Yii 2 is one of the most popular Web programming framework written in PHP language.It can be used for developing all kinds of Web applications from blogs to e-commerce websites and ERP’s. Yii implements the MVC (Model-View-Controller) architectural pattern.

    2. Question 2. Which Php Version Is Required To Install Yii 2.0?

      Answer :

      Yii 2.0 requires PHP 5.4.0 or above and runs best with the latest version of PHP 7 too.

    3. Question 3. What Is Latest Version Yii 2 Framework?

      Answer :

      The latest version of Yii 2 is 2.0.12, released on June 5, 2017.

    4. Question 4. Provide Steps To Install Yii 2 Framework?

      Answer :

      You can install Yii2 by running below commands via composer:

      Composer global require "fxp/composer-asset-plugin:^1.3.1"

      Composer create-project --prefer-dist yiisoft/yii2-app-basic basic

    5. Question 5. List Some Features Yii2 Framework?

      Answer :

      Features of Yii Framework:

      • Model-View-Controller (MVC) design pattern
      • Form input and validation
      • Skinning and theming mechanism
      • Layered caching scheme
      • Unit and functionality testing
      • Automatic code generation
      • Error handling and logging
      • Database Access Objects (DAO), Query Builder, Active Record, DB Migration
      • AJAX-enabled widgets
      • Internationalization and localization
      • Authentication and authorization
      • Extension library
      • Detailed documentation

    6. Question 6. List Some Database Related Functions In Yii 2 Framework?

      Answer :

      Below are list of some database related functions used in Yii 2 Framework

      find(): Creates an yii dbActive QueryInterface instance for query purpose.


      //Getting first record matching with condition

      $user = User::find()->where(['name' => 'Abc'])->one();

      Find All(): Returns a list of active record models that match the specified primary key value(s) or a set of column values.


      // find the customers whose primary key value is 10

      $customers = Customer::find All (10);

      // find customers whose age is 30 and whose status is active

      $customers = Customer::find All (['age' => 30, 'status' => 'active']);

      Insert (): Inserts a row into the associated database table using the attribute values of this record.


      $customer = new Customer;

      $customer->name = $name;

      $customer->email = $email;


      Delete(): Deletes the table row corresponding to this active record.


      $models = Customer::find()->where('status = 3')->all();

      foreach ($models as $model) {



      Delete All(): Deletes rows in the table using the provided conditions.


      Customer::delete All ('status = 3');

      save() :Saves the current record. Usages:

      $customer = new Customer; // or $customer = Customer::find One ($id);

      $customer->name = $name;

      $customer->email = $email;


    7. Question 7. Please List Basic Server Requirements To Install Yii 2 Framework?

      Answer :

      Yii 2 requires PHP 5.4 or above with Mbstring extension and PCRE-support.

    8. Question 8. What Is “gii” In Yii 2 And For What It Is Used?

      Answer :

      Gii is module powerful module provided by Yii framework. It helps you create and generate fully customized forms, models, CRUD for database and more. You can enable Gii by configuring it in the modules property of the application. Depending upon how you created your application,

      you may find the following code is already provided in the config/web.php configuration file:

      $config = [ ... ];

      if (YII ENV DEV) {

          $config['bootstrap'][] = 'gii';

          $config['modules']['gii'] = [

              'class' => 'yii Module',



    9. Question 9. What Is Name Of First File The Loaded When Yii Framework Starts?

      Answer :

      Index.php is first file that is called Yii framework starts. In turn it will create a new object of new YiiwebApplication and start the application.

      require(__DIR__ . '/../vendor/autoload.php');

      require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

      // load application configuration

      $config = require(__DIR__ . '/../config/web.php');

      // instantiate and configure the application

      (new yiiwebApplication($config))->run();

    10. Question 10. Explain Naming Convention In Yii 2 Framework?

      Answer :

      Yii follows below naming conventions:

      • You can define table prefix when using Gii. In your case, you need to set it to tbl_. Then it should generate User Controller instead of TblUserController.
      • The Yii Framework employs a class naming convention whereby the names of the classes directly map to the directories in which they are stored. The root level directory of the Yii Framework is the “framework/” directory, under which all classes are stored hierarchically.
      • Class names may only contain alphanumeric characters. Numbers are permitted in class names but are discouraged. Dot (.) is only permitted in place of the path separator.

    11. Question 11. Explain Request Life Cycle In Yii 2 Framework?

      Answer :

      When handling a user request, Yii 2.0 application will undergo the following stages:

      1. Pre-initialize the application with Application::preinit ();
      2. Set up the error handling;
      3. Register core application components;
      4. Load application configuration;
      5. Initialize the application with Application::init()

      • Register application behaviors;
      • Load static application components;

      6 Raise an onBeginRequest event;
      7. Process the user request.

      • Collect information about the request;
      • Create a controller;
      • Run the controller;

      8. Raise an onEndRequest event;

    12. Question 12. What Are Yii Helpers?

      Answer :

      Helpers are static classes in Yii that simplify common coding tasks, such as string or array manipulations, HTML code generation, and so on. In Yii all helpers are kept under yii helpers namespace.

      You use a helper class in Yii by directly calling one of its static methods, like the following:

      use yii helpers Html;

      echo Html::encode('Test > test');

    13. Question 13. What Are Formatted In Yii2?

      Answer :

      Formatter is Yii application component that is used format view data in readable format for users. By default the formatter is implemented by Yiii18nFormatter which provides a set of methods to format data as date/time, numbers, currencies, and other commonly used formats. You can use the formatter like the following,

      $formatter = Yii::$app->formatter;

      // output: January 1, 2014

      echo $formatter->asDate('2014-01-01', 'long');

       // output: 12.50%

      echo $formatter->asPercent(0.125, 2);

       // output: cebe@example.com

      echo $formatter->asEmail('cebe@example.com'); 

      // output: Yes

      echo $formatter->asBoolean(true); 

      // it also handles display of null values:

      // output: (not set)

      echo $formatter->asDate(null);

    14. Question 14. What Are Components In Yii 2?

      Answer :

      Components are an independent set of code written to perform specific task in controllers.Yii applications are built upon components which are objects written to a specification. A component is an instance of Component or its derived class. Using a component mainly involves accessing its properties and raising/handling its events. The base class Component specifies how to define properties and events.

    15. Question 15. Benefits Of Yii Over Other Frameworks?

      Answer :

      • Like most PHP frameworks, Yii implements the MVC (Model-View-Controller) architectural pattern and promotes code organization based on that pattern.
      • Yii takes the philosophy that code should be written in a simple yet elegant way. Yii will never try to over-design things mainly for the purpose of strictly following some design pattern.
      • Yii is a full-stack framework providing many proven and ready-to-use features: query builders and ActiveRecord for both relational and NoSQL databases; RESTful API development support; multi-tier caching support; and more.
      • Yii is extremely extensible. You can customize or replace nearly every piece of the core’s code. You can also take advantage of Yii’s solid extension architecture to use or develop redistributable extensions.
      • High performance is always a primary goal of Yii.
      • Larger Community.

    16. Question 16. What Is C Model Class In Yii2?

      Answer :

      Yii C Model is the base class that provides the common features needed by data model objects. C Model defines the basic framework for data models that need to be validated. All Models in Yii extends C Model class.

    17. Question 17. What Is Active Record (ar) In Yii?

      Answer :

      Active Record provides an object-oriented interface for accessing and manipulating data stored in databases. An Active Record class is associated with a database table, an Active Record instance corresponds to a row of that table, and an attribute of an Active Record instance represents the value of a particular column in that row. Instead of writing raw SQL statements, you would access Active Record attributes and call Active Record methods to access and manipulate the data stored in database tables.

    18. Question 18. What Is Difference Between “render” And “render Partial” In Yii?

      Answer :

      Render function is used to render a view in Yii with specified layout whereas render partial is used to render only view layout is not included in view.

      RenderPartial is basically used when we have to update a portion of page via AJAX.


      Render ('yourviewname');

      RenderPartial ('yourviewpartial');

    19. Question 19. How To Get Current Url In Yii?

      Answer :

      Yii::app () ->request->getUrl () method is used to get current url in Yii framework.

Popular Interview Questions

All Interview Questions

All Practice Tests

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status