Menu

What is codigniter

Page Contents:

  1. What is a codigniter?
  2. Let’s try it: Welcome to Texinterest
  3. Methods in codigniter
  4. Defining a Default Controller
  • Controller files are located in the application/controllers/ directory.
  • A controller is a class file name that is associated with a URI.

Consider the below URI:

  • url_name.com/index.php/Test/
  • Codigniter would make an attempt to find the controller Test.php in the application/controllers/ directory.

Let’s try it: Welcome to Texinterest

  • Create a file Test.php in the application/controllers/ directory.
        <?php
        class Test extends CI_Controller {
    
                public function index()
                {
                        echo 'Welcome to texinterest';
                }
        }    
  • The first letter of Controller name and class name should be capitalized.
  • Next visit the URL   url_name.com/index.php/Test/
  • You will get the response.
        Welcome to texinterest

Methods in codigniter

  • The index method will always loaded by default.    
  • The another way to show the message "Welcome to texinterest" is
       url_name.com/index.php/Test/index
  • The second method determines which method in the controller get's called
        <?php
        class Test extends CI_Controller {
    
                public function index()
                {
                        echo 'Now you are in index function';
                }
    
                public function one()
                {
                        echo 'Now you are in function 1';
                }
    
                public function two()
                {
                        echo 'Now you are in function 2';
                }
        }
      
     
  • when you call the function url_name.com/index.php/Test/index, You will get the response 
         Now you are in index function
  • when you call the function url_name.com/index.php/Test/one, You will get the response
         Now you are in function 1
  • when you call the function url_name.com/index.php/Test/two, You will get the response
         Now you are in function 2

Defining a Default Controller

  • To specify a default controller, open your application/config/routes.php and set in this your variable.
         $route['default_controller'] = 'Test';