Home >>Codeigniter Tutorial >Codeigniter controller
The controller implements the logical implementation for writing the programme and creating the webpage. The controller serves as an intermediary between the model and the view. The Controller Controls Model as well as view.
Controller always stored inside Application/controllers folder. Condeigniter provides two basic files that is stored inside Application/controllers folder index.html and Welcome.php.
Keep these files as they are don't delete these files. Now Create a new file under the same path(Application/controllers) named "Hello.php"
<?php class Hello extends CI_Controller { public function index() { echo "Hello World"; } } ?>
Save Hello class inside Application/controllers/Hello.php. Here, Hello class inherit an in-built Codeigniter Class CI_Controller.
http://localhost/index.php/controller-name/method-name
Open Your Web browser and type inside "http://localhost/CodeIgniter/index.php/Hello" OR "http://localhost/CodeIgniter/index.php/Hello/index"
Explanation: Here Hello is Controller name and index is method name. By default index method automatically calls so if u want to call then type inside url otherwise leave method name.
<?php class Hello extends CI_Controller { public function index() { echo "Hello World"; } public function about() { echo "About us"; } } ?>
http://localhost/CodeIgniter/index.php/Hello/index
http://localhost/CodeIgniter/index.php/Hello/about