Important information

YII Information

Installing framework:

  1. Setup environmental variables:

Go to My Computer=>Properties=>Advanced=>Environmental Variables=>Add New

In variable name type any name

In variable value typein the path to CLI file.e.g., D:\wamp\www\bin\php\php5.2.9

  1. Go To CMD:

Move to the folder where you have placed your framework.


Cd wamp\www\yiiframework

Cd framework

Yiic webapp D:\wamp\www\projname

This will create a folder in wamp for your project.

 Path for using gii:


 Path for login


 While using GII:

  1. Create Model

  2. Create CRUD

The default user enteries i.e. demo/demo and admin/admin are in components/userIdentity.php file.

 Creating an anchor link:

Put following code in view files:

<?php echo CHtml::link(’<b>’.’ Register Now!’.’</b>’, $this->createAbsoluteUrl(‘user/register’)); ?>

 Creating an anchor link for a static page:

<?php echo $form->checkBox($model,‘terms’); ?> I agree to <?php echo CHtml::link(’<b>’.’ terms and conditions.’.’</b>’, $this->createAbsoluteUrl(‘site/page’, array (‘view’=>‘terms’))); ?>

 For captcha or any registration function you need to add corresponding access control in the controller as well like:

public function accessRules()


	return array(

		array('allow',  // allow all users to perform 'index' and 'view' actions





		array('allow', // allow authenticated user to perform 'create' and 'update' actions




		array('allow', // allow admin user to perform 'admin' and 'delete' actions




		array('deny',  // deny all users





For adding captcha on any form add the code in the view file and then captcha code( public function action) in the controller(For Reference refer to sites controller and contact view).

*After changing fieldname in database, the corresponding "itemView" specified in corresponding view also needs to be changed.For e.g.,

It is specified in the form:

<?php $this->widget(‘zii.widgets.CListView’, array(



)); ?>

in the index file. In this case _view needs to be updated as well for corresponding field name.

 if a new field is added in the database, then, changes must be made to model, views, controller that make use of the corresponding table.

 CVarDumper::dump(varname,depth,true);

For printing variable value.

 Using Scenarios list for validations:

Define scenarios in model file and then specify the scenario n while creating an object on the model class in the controller:

Model file:

array(‘password,passwordagain’, ‘required’,‘on’=>‘register’),

Controller file, inside function:

$model=new User(‘register’);

 Using own conditions inside dataprovider:


     &#036;criteria=new CDbCriteria(array(



     &#036;dataProvider=new CActiveDataProvider('Project', array(









Creating Multi-step form :

//Creating image links

<?php echo CHtml::link(’<img src="’.Yii::app()->baseUrl . ‘/images/postproject.jpg" alt=“View” />’, array(“project/create”)); ?>

//Setting image path for upload

$rootPath = Yii::getPathOfAlias(‘webroot’);

//setting image path for display


//Using templates for mail Body

$body = $this->renderPartial(’/mailtemplates/forgotpassword_mail_tpl’, array(‘username’ => $record->username,‘password’=>$random_number), true);