Thursday, January 8, 2015

Setup new project for Yii Framework

1. Download yii framework from their website
2. Extract and place whole folder into root folder. if its wampp it will be under www folder. if it xampp, under htdocs. The downloaded folder will have:
demos
framework
requirement
CHANGELOG
LICENSE
README
UPGRADE

3. Add below path at environment variable
C:\wamp\www\yii\framework;
C:\wamp\bin\php\php5.4.12;

4. Create new folder of your project inside root folder. Example: personal
5. Run yiic (command line tool) from cmd to create new project. Below code will auto generate
yiic webapp "C:\wamp\www\personal"
6. Default login admin/admin

Setup gii to create model - able to auto generate a page together with crud (create, read, update, delete operation)
1. enable things, find protected/config/main.php line 24
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>false,
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),

2. add menu, find protected/views/layouts/main.php line 31
'items'=>array(
array('label'=>'Gii', 'url'=>array('/gii')),
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
),

3. from gii page, click model generator. choose table to use to create a form/page. the label and input text are taken from table itself. set model name (any name).
4. from gii page, click crud generator. choose the model (newly created). click preview and generate.
5. Review the newly page created here. http://localhost/personal/index.php?r=post simply add the menu for this newly created menu as per below:
'items'=>array(
array('label'=>'Gii', 'url'=>array('/gii')),
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest),
array('label'=>'Post', 'url'=>array('/post'))
),