Codeigniter Basic Concepts
Creating a Controller
First, go to application/controllers folder. You will find two files there, index.html and Welcome.php. These files come with the CodeIgniter.Keep these files as they are. Create a new file under the same path named “Demo.php”. Write the following code in that file ?
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Demo extends CI_Controller {
// Some Code
}
The Demo class extends to CI_Controller. Controller This class must be extended whenever you want to make your own Controller class.
http://www.your-domain.com/index.php/class name
Notice the Class name “Demo” in the above URI after index.php. This indicates the class name of controller. As we have given the name of the controller “Demo”, we are writing “Demo” after the index.php. The class name must start with uppercase letter but we need to write lowercase letter when we call that controller by URI. The general syntax for calling the controller is as follows ?
http://www.your-domain.com/index.php/controller/method-name
Creating & Calling Method
So lets start how to make CodeIgniter first program
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Demo extends CI_Controller {
public function index() {
// This is default function. echo "Hello!";
}
}