YII Interview Questions and Answers
Most Frequently Asked YII Interview Questions
You can set the default controller file through (protected/config/main.php).
array(
'name'=>'Yii Framework',
'defaultController'=>'site',
)
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();
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.
namespace appassets;
use yiiwebAssetBundle;
class DemoAsset extends AssetBundle {
public $basePath = ‘@webroot’;
public $baseUrl = ‘@web’;
public $js = [‘js/demo.js’];
}
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>',
),
],