Codeigniter Controller is simply class name which contains methods inside it.
All the controllers are kept inside the application/controllers folder.
Codeigniter Controller Syntax
Lets start with a simple controller named as “Helloworld”.
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Helloworld extends CI_Controller { function index(){ echo "Hello world."; } } ??> |
Note Class name must start with uppercase
example:
class Helloworld extends CI_Controller { }
Not Like This :
class helloworld extends CI_Controller { // this invalid class name. }
Now visit your site as :
http://localhost/Helloworld
Or
If you have not removed the index.php from url
http://localhost/index.php/Helloworld
Note : Default function index() will be called
Which is :
http://localhost/Helloworld/index