Basic Concepts

Hi I have POST the basic structure of yii how tro render a page so i hope it’s some help.

  1. Download yii folder

  2. Go to var/www directory in terminal

  3. TO create a new project follow:

first you need to get into your webroot by

cd /var/www <– in my case

create a folder that you want your demo to be install in my case I create a folder named ‘blog’ under /var/www/yii/

then set permission to 777 by: sudo chmod 777

then type in the following command

php yii/framework/yiic.php webapp /var/www/yii/blog

if your php program has not been installed, the system will give you an install command then do it and come back to do the same.

then you can access your demo by http://localhost/yii/blog <— in my case

  1. To enable gii

go to protected>config>main.php and uncomment gii module

  1. To access gii generator go to http://localhost/myp...i/default/login

  2. To convert url mapping into path format go to config>main.php and uncomment


‘urlManager’=>array(

‘urlFormat’=>’path’,

‘rules’=>array(

‘<controller:\w+>/<id:\d+>’=>’<controller>/view’,

‘<controller:\w+>/<action:\w+>/<id:\d+>’=>’<controller>/<action>’,

‘<controller:\w+>/<action:\w+>’=>’<controller>/<action>’,

),

),

  1. Passing variable data from controller to view

In Controller


public $message = ‘Hello World rom controller’;


 public function actionIndex()

{

$this->render(‘index’,array(‘content’=>$this->message));

}




Now variable content is available to modified

In View


<?php echo $content ?>

Alternatively we could do


<?php echo $this->message   ?>

  1. CRUD generation

a) Config database

B) Go to protected>>config>>main.php

c) Uncomment db componenent

d) Give the username , password, and db name

e) Comment out sqlite configuration which lie just above the mysql configuration

  1. GO to gii

  2. Select model generator

  3. Enter table details and generate the model

  4. We now have Message.php under model directory

  5. Now click on CRUD generator

  6. Enter Model name

  7. Click generate

  8. You can try it out by goign to baseurl/modelname

  9. Access database content via these codes in controller


public $message = ”;


 public function actionIndex()

{ $message=Message::model()->findByPK(3);

$this->message=$message->content;

$this->render(‘index’,array(‘content’=>$this->message));

}