Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

CodeIgniter Basics: PHP MVC Framework Introduction

PHPCodeIgniter

CodeIgniter is a lightweight PHP framework that follows the Model-View-Controller (MVC) pattern. It gives you a small core, helpers and libraries for routing, database access, forms, validation and sessions, so you can build websites and APIs without wiring everything yourself. This tutorial covers what CodeIgniter is, which version to choose in 2026, how a request flows, and a first controller and view.

Use CodeIgniter 4 for new projects. Version 3 is an old line that does not support modern PHP, so only maintain it where you must.

Table of Contents

  • Why people choose CodeIgniter
  • CodeIgniter 3 versus CodeIgniter 4
  • Installing CodeIgniter 4
  • How a request flows
  • Your first controller and view
  • Next steps
  • Frequently Asked Questions
    • Is CodeIgniter still worth learning?
    • Can I run CodeIgniter on shared hosting?
    • Does CodeIgniter support REST APIs?
    • Which database does it support?
  • Summary

Why people choose CodeIgniter

  • Small footprint and fast: few dependencies and little configuration.
  • Clear MVC structure that is easy for beginners to learn.
  • Works on ordinary shared hosting as well as on VPS and containers.
  • Good documentation on the official site.
  • No command line is required to run a basic site, although CodeIgniter 4 includes the spark CLI, which makes common tasks faster.

For large applications with many packages, teams often compare it with Laravel or Symfony, which have bigger ecosystems.

CodeIgniter 3 versus CodeIgniter 4

FeatureCodeIgniter 3CodeIgniter 4
PHP versionLegacy PHP 5.x and 7.x eraPHP 8.1 or newer for current releases
Namespaces and autoloadingNoYes, with Composer
RoutingConfig arrayRoute collection with groups and filters
CLILimitedspark command
StatusNot suited to new workActively maintained

Check the official documentation for the exact minimum PHP version of the release you install.

Installing CodeIgniter 4

The recommended method is Composer.

bash

Open http://localhost:8080 and you will see the welcome page. Configuration lives in .env, which you copy from the env file and edit for the base URL, environment and database.

How a request flows

  1. The web server sends the request to public/index.php, the single entry point.
  2. The router matches the URL to a controller method using app/Config/Routes.php.
  3. Filters run, for example for authentication or CSRF protection.
  4. The controller asks models for data and loads a view.
  5. The response is sent back to the browser.

Keep the document root pointed at the public folder, never at the project root, so application code and .env are not reachable from the web.

Your first controller and view

Add a route in app/Config/Routes.php:

php

Create the controller app/Controllers/Hello.php:

php

Create the view app/Views/hello.php:

php

Visiting /hello/Asha now shows "Hello, Asha!". The esc() function escapes output and protects against cross-site scripting, so use it for every user-supplied value.

Next steps

Once this works, learn the models and the query builder, then validation, migrations and the spark make: generators. The official user guide for your version is the best reference, at https://codeigniter.com/user_guide/.

Frequently Asked Questions

Is CodeIgniter still worth learning?

Yes, for small and medium projects and for teams that value simplicity. For large systems, compare it with Laravel and Symfony first.

Can I run CodeIgniter on shared hosting?

Yes. Point the document root at public, or upload the files so that only public is web accessible.

Does CodeIgniter support REST APIs?

CodeIgniter 4 has ResourceController and ResponseTrait, which make JSON APIs straightforward.

Which database does it support?

MySQL and MariaDB, PostgreSQL, SQLite, SQL Server and Oracle drivers are available through the database library.

Summary

CodeIgniter is a compact PHP MVC framework that is quick to learn. Start new projects on CodeIgniter 4, install with Composer, keep public as the web root, escape output with esc(), and use controllers, models and views to keep code organised.

Share

Similar posts

  • How to Make a Simple REST API in CodeIgniter 4
  • How to Use Grunt in CodeIgniter to Minify CSS and JavaScript
  • How to Do Error Logging in CodeIgniter
  • How to Do Error Logging in CodeIgniter 3 and 4
  • PayU Payment Gateway Integration in CodeIgniter 4
  • How Do You Create and Access Arrays in PHP?
  • How Do include and require Differ in PHP?
  • What Is Recursion in PHP with Examples?