Articles → PHP CODEIGNITER → Create your first controller in codeigniter

Create your first controller in codeigniter






What is the controller?





Where do you find the controllers?




Picture showing the folder structure in codeigniter

Click to Enlarge


Create your first controller








<?php
defined('BASEPATH') or exit('No direct script access allowed');

class About extends CI_Controller
{
    public function Index()
    {
        $this->load->view('About');
    }
}








Picture showing 'About' view file

Click to Enlarge



Picture showing the output of controller in the browser

Click to Enlarge


Index function






<?php
defined('BASEPATH') or exit('No direct script access allowed');

class About extends CI_Controller
{
    public function CallAbout()
    {
        $this->load->view('About');
    }
}




Picture showing the 404 error message when index function is accessed after renaming it

Click to Enlarge



Picture showing the output of controller with function name 'CallAbout'

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Friday, July 10, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250