Change language

Introduction to Codeignitor (PHP)

Why use Codeignitor?
  • Fast and lightweight because the library uses less memory.
  • Easy to learn how to make a mid-range project.
  • Clear documentation to make it easy to understand and build the project yourself
  • Easy error handling, easy debugging and security troubleshooting.
  • A lot of community and developer support is available on worldwide.
  • Paging support, encryption, file upload class, built-in class for sending email.
  • Codeignitor download:Download Codeignitor and save it in the htdocs folder with your project name, let’s say ci_tutorial. Then run this project on your local hostwith the URL http: // localhost / ci_tutorial . Below is the output when codeignitor is installed and successfully launched on localhost. 
    Directory structure:There are basically three folders in the Codignitor directory structure ... This is app, system and user_guide. Most of the work will be done in the application folder, where, along with other folders, the model, view, controller folder will be available. Below is a picture of the directory structure. 
    Below is the structure of the application folder in which the developer performs most of the tasks. 
    How it works:Main codeignitor file - index.php, so if you run http: //localhost/ci_tutorial/index.phpin a browser, you get the same "Welcome to Codeignitor" view. Now open the route.php file,which is located in the config folder. There you will find the default controller name at the end of the file.
    $route [’default_controller’] =’ welcome’; 
    The above code specifies that by default CI launches the welcome controller. and this file is available in the Controller folder named Welcome.php. You can change the default controller name here. Once you open the Welcome.php controller in the Controller folder, you will find the index function, which is the default Welcome controller function.
    public function index() {$this-> load-> view (’ welcome_message’); } 
    The above index function loads the view file ’ welcome_message ’ from the browse folder. So the whole concept is that routing tells which one is the default controller, then clicks on that controller, and then the index function (default) of that controller will look at the file defined in that function. 
    The index function in any controller is the default function. To run any other controller or function (besides the index function) in the controller, you can define it manually in the URL after creating the controller and its function in the folder. Let’s see how to do it. 
    Create a controller Test.php (controller name must start in uppercase) in the controller folder and write the code below. defined ( ’BASEPATH’ ) OR exit ( ’No direct script access allowed’ ); class Test extends CI_Controller { public function index() { $this -> load-> view ( ’test_message’ ); } public function test_demo() { $this -> load-> view ( ’test_tutorial’ ); } }
    Now create a view file test_message.php, write the below code and save it in your watch folder. defined ( ’BASEPATH’ ) OR exit ( ’No direct script access allowed’ ); ?> "en" >

    Welcome to GeeksforGeeks

    < / html >
    Now in your browser enter this URL http: //localhost/ci_tutorial/index.php/Test . You will find below the result
    So , here in the url put the name of the controller after index.php that will run the default index.php method from the test controller. 
    Now create a test_tutorial.php file in your watch folder and write the code below. defined ( ’BASEPATH’ ) OR exit ( ’ No direct script access allowed’ ); ?> "en" >

    This is the test tutorial

    < / html >
    Now run the URL http: // localhost / ci_tutorial / index.php / Test / test_demoin your browser and below is the result. 
    So to run any other to a function from a controller, just specify the controller name and then the function name in the URL after index.php.


    Best laptop for Sims 4


    Best laptop for Zoom


    Best laptop for Minecraft


    Best laptop for engineering student


    Best laptop for development


    Best laptop for Cricut Maker


    Best laptop for hacking


    Best laptop for Machine Learning


    Latest questions


    psycopg2: insert multiple rows with one query

    12 answers


    How to convert Nonetype to int or string?

    12 answers


    How to specify multiple return types using type-hints

    12 answers


    Javascript Error: IPython is not defined in JupyterLab

    12 answers


    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method