YII Interview Questions and Answers

Last updated on Feb 06, 2023
  • Share
YII Interview Questions

Most Frequently Asked YII Interview Questions

Here in this article, we will be listing frequently asked YII Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q21. List some database related query functions in Yii?
Answer
Q22. How we can set default controller in Yii?
Answer

You can set the default controller file through (protected/config/main.php).
array(
    'name'=>'Yii Framework',
    'defaultController'=>'site',
)

Q23. How to use form validations in Yii?
Answer
Q24. How to use session in Yii?
Answer

Create Session

Yii::app()->session['name'] = "umesh singh";

Get value from session

$name = Yii::app()->session['name'];

Unset session like

unset(Yii::app()->session['name']);

Remove all session

Yii::app()->session->clear();

Remove session from server

Yii::app()->session->destroy();

Q25. What is widgets in Yii? How we can use it?
Answer

Widgets are instances of CWidget or their child class. This component is primarily for presentational purposes and is embedded in the view script to help generate a complex UI.

Q26. How to use asset Bundles in Yii?
Answer

namespace appassets;

use yiiwebAssetBundle;

class DemoAsset extends AssetBundle {

public $basePath = ‘@webroot’;

public $baseUrl = ‘@web’;

public $js = [‘js/demo.js’];

}

Q27. How to enable the pretty URL format in Yii2?
Answer

Create an .htaccess file and add this code.

RewriteEngine on

# If a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward it to index.php

RewriteRule . index.php

2. Now Modify common/config/main-local.php

'urlManager' => [
   'class' => 'yii\web\UrlManager',
   'showScriptName' => false,   
   'enablePrettyUrl' => true,
   'rules' => array(
      '<controller:\w+>/<id:\d+>' => '<controller>/view',
      '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
      '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
   ),
],
Reviewed and verified by Umesh Singh
Umesh Singh

My name is Umesh Singh having 11+ experience in Node.JS, React JS, Angular JS, Next JS, PHP, Laravel, WordPress, MySQL, Oracle, JavaScript, HTML and CSS etc. I have worked on around 30+ projects. I lo...