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




  1. Create a new file "About.php"
  2. Inside the controller, add the following command
<?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