CodeIgniter Forums
Simple MVC example. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Learn More (https://forum.codeigniter.com/forumdisplay.php?fid=15)
+--- Thread: Simple MVC example. (/showthread.php?tid=1131)



Simple MVC example. - Ujitha - 02-13-2015

In this post I will show you how to do basic MVC examples.


Step 01 :

Frist I will create my controller.
So create a file called name.php in \CodeIgniter\application\controllers directory.

And paste the below codes.

<?php

class name extends CI_Controller{

public function getName()
{

$this->load->model('nameModel');
$data['info']=$this->nameModel->getName();

$this->load->view('name',$data);

}

}


?>

Step 02 :

Now I need my model.Create nameModel.php inside \CodeIgniter\application\models directory.
And save the below set of codes in it.

<?php

class nameModel extends CI_Model{


public function getName()
{

$name="Ujitha";

return $name;


}



}

?>

Step 03 :

Now what I need to do is to view the data to the user.

Create a php file in \CodeIgniter\application\views directory as name.php

save below codes in it.

<?php

echo $info;

?>

Step 04 :

That is all..

Go to the web browser and type the below in address bar(N.B->Here I use the WAMP server.).

http://localhost/Codeigniter/index.php/name/getName


You will have below attached output.


RE: Simple MVC example. - Narf - 02-13-2015

Please, don't use the forum as your personal blog ...