Yii PHP Framework Interview Questions

15 TOP Yii PHP Framework Interview Questions

Yii PHP Framework Interview Questions
Yii PHP Framework Interview Questions

1) What is Yii Framework?
Yii is an open source, web application framework based on MVC. It is written in PHP and used to design PHP applications. This application was started on January and completed in December 2008.

2) Why does Yii Framework run so fast?
Yii Framework run so fast because it uses sluggish loading technique which does’t include class file until the class is initially used.

3) What are the features of Yii Framework?
There are various features of Yii Framework:
It uses MVC design pattern
Web Service available for Apps like android
Internationalization and localization translation for multilingual.
It provides Caching for speed up the application
It manages Error handling and logging for tracking
It provides cross-site scripting (XSS), cross-site request forgery (CSRF) protection
It provides PHP unit and Selenium for testing.
It provides automatic code generation that helps to fast development etc.

4) How can we define a form model?
We can define a form model in Yii1.1 by using following code:

class MyLoginForm extends CFormModel


public $username;

public $password;

public $rememberMe=false;


5) What are the components available in Yii Framework?
There are following components available in Yii Framework:
db: It is used for database connection.
AssetManager: It manage the publishing of private assets files
authManager: It manages role-based access control
cache: It manages caching functionality
clientScript: It manages javascript and CSS
coreMessages: It provides translated core messages
errorHandler: It manages errors handling.
ThemeManager: It manages themes
urlManager: It provides URL parsing and creation functionality
statePersister: It provides mechanism for persisting global state
session: It manages session
securityManager: It manages Security

6) Which file loaded firstly while run a Yii application?
In Yii Framework, index.php file loaded first to display home page of the application.

7) How can we install or setup Yii Framework in our local system?
We can install or setup Yii Framework by using following given steps:
Download the Yii setup from its official website or github.
Extract the code into our server root directory.
Open command line terminal and type the following command.
php path-to-yii-folder/framework/yiic webapp [webapp-name]
After execution of above command, it will ask for the confirmation of creating a new application, on selecting yes, it will create an application.

8) What is the Yii application life cycle?
Yii application life cycle includes the following steps:
Pre-initialize the application with Capplication::preinit()
Set up the class autoloader and error handling
Register core application components
Load application configuration
Initialize the application with Capplication::init()
Register application behaviors
Load static application components
Raise an onBeginRequest event
Process the user request
Collect information about the request
Create a controller
Run the controller
Raise an onEndRequest event

9) What are the database related functions in Yii?
In Yii, databse releted functions are:

10) How can we connect to the database in Yii?
In Yii, we can connect database by using following code:
We can configure database related settings in the main.php file reside into the config folder.

11) What is a YiiBase in Yii Framework?
In Yii Framework, YiiBase is a helper class that provides functionalities of common framework. We should not use YiiBase directly, if we want to access helper class, we have to use its child class where we can customize the methods of YiiBase.

12) What is “gii” and how it works in Yii Framework?
In Yii Framework, gii is a module that provides Web-based code generation capabilities to the developer. We need to change the main configuration file of our application.
return array(




‘password’=>[*choose a password*]




13) How can we access application components in Yii Project?
We can access an application component by using following code:


Where, ComponentID refers to the ID of the component.

14) How can we get current controller id in Yii ?
We can get current controller in Yii Framework by using given code:

$controllerid = Yii::app()->controller->id;

15) How can we set default controller in our Yii Project ?
We can set default controller in our Yii Project by using given code:


‘name’=>’Yii Framework’,



16) What is the difference between “render” and “renderpartial” in Yii Framework?
In Yii Framework, render() is commonly used to render a view that corresponds to what a user sees as a “page” in your application.

renderPartial() is used to render a web page without layout.

Real Time Yii PHP Framework Interview Questions