Adding sub controllers in Codeigniter
In Codeigniter the index() method is always loaded by default if the second segment of the URI is empty. Like this :
http://localhost/myApp/index.php/Hello
Other than this if we want to load a another method from the same URL then we may add other methods as sub controllers.
Example (Hello.php)
<?php class Hello extends CI_Controller { public function index() { echo "Hello World!"; } public function anotherMethod() { echo "Hello another method"; } }
Output
URL : http://localhost/myApp/index.php/Hello/anotherMethod
Output : Hello another method