CodeIgniter Controllers

Controllers take care of moving the data between the model and the views and directing traffic
based on user actions. For example, when a user submits a form, the controller collects the data and
shuffles it off to the model, which should ensure the data is valid. The controller then tells the View
(or JavaScript layer) whether it was successful.
How Controllers Work 
Before I explain how, let’s  look at the routes.php file. This file of this  Application->Config>routes.php.
Routes.php File
when we browse http://localhost/codeigniter/, CI will look for the welcome controller and by default call the index method.
If we add an entry in routes.php

$route['home_page'] = 'welcome/home_page';

then browse url http://localhost/codeigniter/home_page, CI will look for a method name home_pagein Welcome controller.
Source code of Welcome controller

defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
	public function index()

 class Welcome extends CI_Controller:  class Welcome extends(inherit)  the CI core controller.
public function index() :  This function is executed when the home page  is browsed.

Leave A Reply

Your email address will not be published.

  1. Josephine Alberto says

    Thanks for sharing with us. Keep it up.

  2. Josephine Alberto says

    Thanks for sharing with us. Keep it up.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy