Welcome

to

Yii Training

Prepared by

Shamsher Ansari

Day 2

  1. Fundamentals
    • Entry script
    • Application
    • Components
    • Module
    • Conventions
  2. Code Generations
    • GII tool
    • creating actions
    • creating access rules
    • creating models
    • creating views
    • creating forms

Entry script

Initially handles user Requests.

						
						// change the following paths if necessary
						$yii=dirname(__FILE__).'/../yiicore/framework/yii.php';
						$config=dirname(__FILE__).'/protected/config/main.php';

						// remove the following lines when in production mode
						defined('YII_DEBUG') or define('YII_DEBUG',true);

						// specify levels of call stack should be shown in each log message
						defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

						require_once($yii);
						Yii::createWebApplication($config)->run();
						
					
  • DEBUG Mode
  • PRODUCTION Mode

Application

Keeps Application Level Configurations ''front-controller''

  1. Application Configuration.
    • protected/main/config.php
  2. Application Base Directory.
    • protected folder
  3. Application Components.
    • components array in config.php file
  4. Core Application Components.
    • CDbConnection
    • CHttpRequest
    • CUrlManager
    • CErrorHandler

Components

Class, allows access to its properties and events.

  1. Component Property
    • Public Member Variable
  2. Component Event
    • Event Handler.
    • Starts with ''on''.
    • CEvent class.
    • Function with Parameters.

Module

Self-contained software unit includes MVC

						
							'modules'=>array(
								// uncomment the following to enable the Gii tool
								'gii'=>array(
									'class'=>'system.gii.GiiModule',
									'password'=>'gii',
									// If removed, Gii defaults to localhost only.
									'ipFilters'=>array('127.0.0.1','::1'),
								),
							),
						
					
  1. Used in Large Scale Applications.
  2. Best example is Gii.
  3. User and Comment Management.

Conventions

Standards for writing application.

  1. URL
    • http://hostname/index.php?r=ControllerID/ActionID
  2. Code
    • Variables, Functions and Class as CamelCase
  3. Configuration
    • Array of key-value Pair
  4. Database
    • Table and columns in Lower case.
    • Separate words with name using underscore
    • Table name singular.
    • Table prefix eg: tbl_

GII tool

Web-based code generation tool.

						
							'modules'=>array(
								// uncomment the following to enable the Gii tool
								'gii'=>array(
									'class'=>'system.gii.GiiModule',
									'password'=>'gii',
									// If removed, Gii defaults to localhost only.
									'ipFilters'=>array('127.0.0.1','::1'),
								),
							),
						
					

Questions ?

Ask Google

"No one knows better then Google"

THANK YOU

Shamsher Ansari