Good morning my dear friends I am going to again the pervious game again because It is very valuable to understand MVC structure.
Let's go....
First what you need a controller..
Controller has few naming conventions.
1. Contoller should a certain name and suffix "Controller"
Eg: AnimalController
Here Animal is the controller name and "Controller" is suffix.
ok...let us create a simple controller.
<?php
class AnimalController extends controller{
}
?>
2. Now we need action inside the AnimalController.It also have naming conventions.
It should have the prefix action and the name of the action.
ok..let us create the full class with action.
<?php
class AnimalController extends controller{
public function actionName(){
$this->render('name');
}
}
?>
See the above function name.It is 'actionName'.Name is action name and Name is the name of it.
Save it is AnimalController.php in C:\wamp\www\yii\myyii\protected\controllers (According to my pevious lessons).
3.Now we need a view.There is a naming convention to create the view also.
The name of the view should be same as the name of the action.
Eg: our view sholud be as name.php
<?php
echo("Animal name is Cat");
?>
To save above first you need to create a folder in C:\wamp\www\yii\myyii\protected\views as animal.
The name of this folder should be same to the name of the controller.
Let's go....
First what you need a controller..
Controller has few naming conventions.
1. Contoller should a certain name and suffix "Controller"
Eg: AnimalController
Here Animal is the controller name and "Controller" is suffix.
ok...let us create a simple controller.
<?php
class AnimalController extends controller{
}
?>
2. Now we need action inside the AnimalController.It also have naming conventions.
It should have the prefix action and the name of the action.
ok..let us create the full class with action.
<?php
class AnimalController extends controller{
public function actionName(){
$this->render('name');
}
}
?>
See the above function name.It is 'actionName'.Name is action name and Name is the name of it.
Save it is AnimalController.php in C:\wamp\www\yii\myyii\protected\controllers (According to my pevious lessons).
3.Now we need a view.There is a naming convention to create the view also.
The name of the view should be same as the name of the action.
Eg: our view sholud be as name.php
<?php
echo("Animal name is Cat");
?>
To save above first you need to create a folder in C:\wamp\www\yii\myyii\protected\views as animal.
The name of this folder should be same to the name of the controller.
Inside this folder save the above code as name.php
.Now you need to access the controller file.
To do this you need a URL.
Here is the URL.
localhost/yii/myyii/index.php?r=animal/name
Now you will have the below output.
.Now you need to access the controller file.
To do this you need a URL.
Here is the URL.
localhost/yii/myyii/index.php?r=animal/name
Now you will have the below output.
That is all.Be happy..................:)