Yii Interview Questions Answers: Yii is an open source, object-oriented, component-based MVC PHP web application framework.
Q: What is Yii?
Yii is an open source, high-performance, object-oriented, component-based MVC (Model View Controller PHP web application framework. Yii is pronounced as "Yee" or [ji:] and in Chinese it means "simple and evolutionary" and it can be acronym for "Yes It Is!".
Q: What is Yii best for?
Yii is a generic Web programming framework that can be used for developing virtually any type of Web application. Because it is light-weight and equipped with sophisticated caching mechanisms, it is especially suited to high-traffic applications, such as portals, forums, content management systems (CMS), e-commerce systems, etc.
Q: Why Yii is so FAST : Most frequently asked Yii Interview Questions Answers?

Yii is so much faster because it is using the lazy loading technique extensively.

For example: it does not include a class file until the class is used for the first time, and it does not create an object until the object is accessed for the first time. Other frameworks suffer from the performance hit because they would enable a functionality (e.g. DB connection, user session) no matter it is used or not during a request.
Q: How to install Yii framework ?
Yii 2 Installation Process  step by step
Q: What are main feature of Yii framework?
  1. Model-View-Controller (MVC) design pattern
  2. Database Access Objects (DAO), Query Builder, Active Record, DB Migration
  3. Form input and validation
  4. AJAX-enabled widgets
  5. Skinning and theming
  6. Web Service available for Apps like android
  7. Internationalization and localization translation for multilingual
  8. Caching for speed up the application
  9. Error handling and logging for tracking
  10. Security: cross-site scripting (XSS), cross-site request forgery (CSRF) protection
  11. PHPUnit and Selenium for testing
  12. Automatic code generation help us to fast development
  13. Authentication and authorization
  14. Friendly with third-party code
  15. Extension library
Q: What is the component, helper in Yii2?

Component: A component is an independent piece of code written for specific task that can be used by calling in controllers (example : email component).

Helper: Yii provides many classes that help simplify common coding tasks, such as string or array manipulations, HTML code generation, and so on. These helper classes are organized under the yii\helpers namespace and are all static classes (meaning they contain only static properties and methods and should not be instantiated).

You use a helper class by directly calling one of its static methods, like the following:
use yii\helpers\Html; echo Html::encode('Test > test');

Types

  1. Core Helper Classes
  2. Customizing Helper Classes

1. Core Helper Classes

The following core helper classes are provided in the Yii releases:
  • ArrayHelper
  • Console
  • FileHelper
  • FormatConverter
  • Html
  • HtmlPurifier
  • Imagine (provided by yii2-imagine extension)
  • Inflector
  • Json
  • Markdown
  • StringHelper
  • Url
  • VarDumper

2. Customizing Helper Classes

To customize a core helper class (e.g. yii\helpers\ArrayHelper), you should create a new class extending from the helpers corresponding base class (e.g. yii\helpers\BaseArrayHelper) and name your class the same as the corresponding concrete class (e.g. yii\helpers\ArrayHelper), including its namespace. This class will then be set up to replace the original implementation of the framework.

these only adds to modularity in code otherwise same coding can be implemented in controllers.

Q: What are the core components of Yii2?
  1. db- database connection.
  2. assetManager - manage the publishing of private asset files
  3. authManager - manage role-based access control
  4. cache- manage caching functionality
  5. clientScript- manage javascript and CSS
  6. coreMessages- provides translated core messages
  7. errorHandler- manage errors handling.
  8. themeManager- Manage themes
  9. urlManager- URL parsing and creation functionality
  10. statePersister- mechanism for persisting global state
  11. session- Session management
  12. securityManager- Security Managment
Q: How to Create Custom Component in Yii2
Q: How to get current controller name?
//Controller Name echo Yii::$app->controller->id;
Q: How to get current action name?
echo Yii::$app->controller->action->id;
Q: What is the first function that gets loaded from a controller?
index
Q: How can we use ajax in Yii?
use ajax helper
Q: What is the differences between render , renderPartial and renderfile in yii framework ?

render() is commonly used to render a view that corresponds to what a user sees as a “page” in your application. It first renders the view you have specified and then renders the layout for the current controller action (if applicable), placing the result of the first render into the layout. It then performs output processing and finally outputs the result. i.e) render with theme.

renderPartial() is commonly used to render a “piece” of a page. The main difference from render() is that this method does not place the results of the render in a layout. By default it also does not perform output processing, but you can override this behavior using the $processOutputparameter. i.e) render without theme.

renderFile() is a low-level method that does the grunt work of rendering: it extracts the data variables in the current scope and then runs the view code. The other two methods internally call this one, but you should practically never need to call it yourself. If you do, keep in mind that you need to pass in a file path (not a view path).

Q: Server requirements to install Yii2?
Yii2 requires following things:
  1. PHP 5.4 or above
  2. mbstring extension
  3. PCRE-support
Q: Which ORM does Yii2 supports?

Active Record, it provides an object-oriented interface for accessing and manipulating data stored in databases.

Q: What is Gii in Yii2?

Gii is a web-based code-generator module provided by Yii framework

It helps you create and generate fully customized forms, models, CRUD for database and more

To view more, please visit Yii2 Official Website