CI 4 Create First Program

We will create first program in CodeIgniter 4. So, we need a Controller file, a view file and a route.

Create Controller

Open project setup into terminal and run this spark command into it.

$ php spark make:controller Site --suffix

It will create SiteController.php inside /app/Controllers folder. Open file and write this code.


namespace App\Controllers;

use App\Controllers\BaseController;

class SiteController extends BaseController
	public function index()
		return view("site-view");

We have done with the controller.

Next, create a view file.

Create View File

Create site-view.php inside /app/Views folder.

Open site-view.php and write this code into it.

<h2>Hi, This is my first page in CodeIgniter 4</h2>

Now, we need a route.

Create Route

Open Routes.php from /app/Config folder. Open file and add this route into it.


$routes->get("/first-page", "SiteController::index");

Finally, everything is perfect.

Start Development Server

Back to project terminal and run this spark command.

$ php spark serve

It will start application in development server at 8080 port.

Open browser, URL – http://localhost:8080/first-page


Hi, This is my first page in CodeIgniter 4

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more