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
- Navigate to the
application/controllers
directory in your CodeIgniter project. - Create a new PHP file named
Hello.php
. - Open
Hello.php
and define a new controller class calledHello
:
<?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
- Start your local web server (e.g., Apache, Nginx).
- Navigate to the base URL of your CodeIgniter application in a web browser.
- If everything is set up correctly, you should see the "Hello, World!" message displayed in the browser.
Comments