My dear friends today I am going to play with Yii..That is being familier with Yii MVC.
Come on...Let us go..
Now according to the previous lessons we have the below directory.
C:\wamp\www\yii\myyii
That is you have a folder called myyii inside the yii folder.
Ok click on the protected folder and you will see folders named as Model,View,Controller.
Let us play a simple game.
I will just write a URL and describe it.Then you will understand what is going on in Yii MVC.
My URL is as shown below.
http://localhost/yii/myyii/index.php?r=vehical/create
Here vehical is the controller name and create is the action name.index.php is your default page which has got links to config and other needed files.
I will describe it you.
First you need a controller.
So type the below codes and save it as VehicalController.php in C:\wamp\www\yii\myyii\protected\controllers directory.
Read the comments I have given carefully.
<?php
class VehicalController extends Controller{ //VehicalController is the name of the Controller.
public function actionCreate(){//actionCreate is the name of the function.
$this->render('create');//This will call the create file in view.
}
}
?>
Now we need a view file.So type below codes in a text editor.
First you need to create a folder called vehical inside the below directory.
C:\wamp\www\yii\myyii\protected\views
The name of the folder should be same with the name of the Controller name.
Inside that folder save the below codes as create.php
The name of this file should be same as the name of the function name.
<?php
echo("Ishani Bandara");
?>
Now every thing is ok...
Go to the address bar of the browser and type below code.
You will have the below output..
That is all...Be happy and understand the conventions and case of the letter carefully.....
Come on...Let us go..
Now according to the previous lessons we have the below directory.
C:\wamp\www\yii\myyii
That is you have a folder called myyii inside the yii folder.
Ok click on the protected folder and you will see folders named as Model,View,Controller.
Let us play a simple game.
I will just write a URL and describe it.Then you will understand what is going on in Yii MVC.
My URL is as shown below.
http://localhost/yii/myyii/index.php?r=vehical/create
Here vehical is the controller name and create is the action name.index.php is your default page which has got links to config and other needed files.
I will describe it you.
First you need a controller.
So type the below codes and save it as VehicalController.php in C:\wamp\www\yii\myyii\protected\controllers directory.
Read the comments I have given carefully.
<?php
class VehicalController extends Controller{ //VehicalController is the name of the Controller.
public function actionCreate(){//actionCreate is the name of the function.
$this->render('create');//This will call the create file in view.
}
}
?>
Now we need a view file.So type below codes in a text editor.
First you need to create a folder called vehical inside the below directory.
C:\wamp\www\yii\myyii\protected\views
The name of the folder should be same with the name of the Controller name.
Inside that folder save the below codes as create.php
The name of this file should be same as the name of the function name.
<?php
echo("Ishani Bandara");
?>
Now every thing is ok...
Go to the address bar of the browser and type below code.
You will have the below output..
That is all...Be happy and understand the conventions and case of the letter carefully.....