Interview questions for 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.

1) What is Yii 2 ? Please Explain?

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) What are Yii helpers?

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’);

3) List Some Features Yii2 Framework?

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

4. What are formatter in Yii2 ?

Formatter are Yii application component that is used format view data in readable format for users. By default the formatter is implemented by yii\i18n\Formatter 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)

5. Explain Naming Convention In Yii 2 Framework?

Yii follows below naming conventions:
o 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.
o 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.
o 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.

6. What Is Active Record (ar) In Yii?

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.

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

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.
Usage
Render (‘yourviewname’);
RenderPartial (‘yourviewpartial’);

8. What are the Core Helper Classes in the Yii framework?

The following core helper classes are:
o ArrayHelper
o Console
o FileHelper
o FormatConverter
o Html
o HtmlPurifier
o Imagine
o Inflector
o Json
o Markdown
o StringHelper
o Url
o VarDumper

9. What is CActiveRecord in the Yii framework?

o Active Record (AR) is a design pattern used to abstract database access in an object-oriented fashion. Each AR object is an instance of CActiveRecord or a subclass of that class, representing a single row in a database table.
o The fields in the row are represented as properties of the AR object. All AR details are found in Active Record.

10.  How to get the current url in Yii?

o Yii::app()->request->getUrl() method is used to get current url in Yii framework.
o ________________________________________
o 41) How to set Home page Url in Yii?
o You can use the below code to set the Home Page Url:

11.  What are Components in Yii 2 ?

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 CComponent or its derived class. Using a component mainly involves accessing its properties and raising/handling its events. The base class CComponent specifies how to define properties and events.

12. What is CModel Class in Yii2?

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

13. What is Active Record(AR) in yii ?

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.

leave your comment


Your email address will not be published. Required fields are marked *