Yesterday I describe you about the file structure of the CI framework. Today I will show you how to run a simple
example in CI.
First open an empty file in any text editor and I use sublime text editor.
Now I am going to create my MVC.
1. First I create my controller.
Save this file as show.php in \CodeIgniter\application\controllers directory.
The show.php is like this..........
<?php
class show extends CI_Controller{
public function give(){
$this->load->model('showmodel'); // Here we are loading the model and the name //of my model is "showmodel".
$data['info']=$this->showmodel->get(); //Here I am calling a method called get() //in the showmodel and assign returned values to array //called $data['info'] .
//N.B In CI we use arrays to pass the data to the view.
$this->load->view('myview',$data); //we sene the data to view.Here I have create a //view called 'myview' and pass the $data
}
}
?>
2 . Now I need to create my model.Save the below codes in \CodeIgniter\application\models directory as showmodel.php
Here is my model
<?php
class showmodel extends CI_Model{
public function get(){
$name="Manuja";
return $name;
}
}
?>
3. Now I create my view file.Save below codes as myview.php in \CodeIgniter\application\views directory .
Here is my view file
<?php
echo $info; //see the array in controller.Although we pass $data to the view we print //$info. Try to remember it.
?>
4. Now it is all over.Go to the web browser and type as follows..
http://localhost/codeigniter/index.php/show/give
If you see the folowing output you have done it.
example in CI.
First open an empty file in any text editor and I use sublime text editor.
Now I am going to create my MVC.
1. First I create my controller.
Save this file as show.php in \CodeIgniter\application\controllers directory.
The show.php is like this..........
<?php
class show extends CI_Controller{
public function give(){
$this->load->model('showmodel'); // Here we are loading the model and the name //of my model is "showmodel".
$data['info']=$this->showmodel->get(); //Here I am calling a method called get() //in the showmodel and assign returned values to array //called $data['info'] .
//N.B In CI we use arrays to pass the data to the view.
$this->load->view('myview',$data); //we sene the data to view.Here I have create a //view called 'myview' and pass the $data
}
}
?>
2 . Now I need to create my model.Save the below codes in \CodeIgniter\application\models directory as showmodel.php
Here is my model
<?php
class showmodel extends CI_Model{
public function get(){
$name="Manuja";
return $name;
}
}
?>
3. Now I create my view file.Save below codes as myview.php in \CodeIgniter\application\views directory .
Here is my view file
<?php
echo $info; //see the array in controller.Although we pass $data to the view we print //$info. Try to remember it.
?>
4. Now it is all over.Go to the web browser and type as follows..
http://localhost/codeigniter/index.php/show/give
If you see the folowing output you have done it.
N.B Look at the URL here show is the controller name and give is the function name.This is how we access the pages in CI.
Be fun!!!!
-Manuja-
Be fun!!!!
-Manuja-