Friday, December 7, 2018

How to work with controllers in CodeIgniter


Controllers are the ones that receive the HTTP requests, communicate with models to get the data, send it to views to generate the HTML code and return the results to the web browser. In this tutorial, we will look at how we can use Controllers in CodeIgniter and create our own controller(s) that will extend the CodeIgniter core Controller class. This tutorial assumes you read the article on how to install and configure a CodeIgniter project. We assume you have removed the index
HERE,
  • “$route['default_controller'] = 'welcome';” defines welcome as the default controller.
  • ['custom_controller'] = 'welcome';” defines welcome as the default controller.
  • When you browse the URL localhost/Test_CI/, CodeIgniter will look for a controller named Test and by default will call the testindex method.
      <?php
      defined('BASEPATH') OR exit('No direct script access allowed');

      class Test extends CI_Controller {

      public function testindex()
      {
      echo "hello ";
      echo "welcome ";
      }
      public function user(){
      echo "hello ixora";
      }
      }
          HERE,
        • “class Test extends CI_Controller” defines the class Test and extends the codeigniter core controller.
        • “public function testindex()” is the function and here methode name is testindex

No comments:

Post a Comment