Passing parameters to your controller methods in Codeigniter

If your URI contains more then two segments they will be passed to your method as parameters.
For example, let’s say you have a URI like this:
localhost/myApp/index.php/Hello/anotherMethod/1234

Example

<?php
class Hello extends CI_Controller {
	public function index()
	{
		echo "Hello World!";
	}

	public function anotherMethod($id)
	{
		echo "Hello id : " . $id;
	}
}

Output

URL : http://localhost/myApp/index.php/Hello/anotherMethod/1234
Output : Hello id : 1234

Share

You may also like...