difference between index, construct and class name functions in codeigniter class difference between index, construct and class name functions in codeigniter class codeigniter codeigniter

difference between index, construct and class name functions in codeigniter class


function Upload() is a PHP4 thing. That is the constructor function for the Upload object, this is deprecated.

__construct() is the 'new' way of doing constructors

index() gets called on the index action, which is the default action

Visiting /uploads or /uploads/index will run this function. The other two functions will always run.

Hope this clears it up!


You really need to start over with a blank screen and read through the documentation on Codeigniter Controllers.

and make sure you are using CI 2.0

edited version (corrected for CI 2.0)

<?class Upload extends CI_Controller{    function  __construct()    {       parent::__construct();       echo 'test';    }    function index()     {       echo 'test';    }}

__construct() gets called every time the controller is loaded

index() is the default function that is called if no function is given in the uri

ex. localhost/index.php/upload will actually call localhost/index.php/upload/index/