Create New Post

Creating a simple "Hello World" application

Creating a simple "Hello World" application in CodeIgniter is a great way to get started and understand the basic structure of a CodeIgniter project. Follow these steps to create a "Hello World" application:

Step 1: Install CodeIgniter

If you haven't already installed CodeIgniter, download it from the official website and extract the contents to your web server directory.

Step 2: Create a Controller

  1. Navigate to the application/controllers directory in your CodeIgniter project.
  2. Create a new PHP file named Hello.php.
  3. Open Hello.php and define a new controller class called Hello:

 

 

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

class Hello extends CI_Controller {
    public function index() {
        echo "Hello, World!";
    }
}
?>

Step 3: Define a Route

By default, CodeIgniter routes URLs to controllers/methods using the index() method. Therefore, we don't need to define a custom route for this simple example.

Step 4: Access the Application

  1. Start your local web server (e.g., Apache, Nginx).
  2. Navigate to the base URL of your CodeIgniter application in a web browser.
  3. If everything is set up correctly, you should see the "Hello, World!" message displayed in the browser.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

82414