Overview

CodeIgniter is a powerful PHP framework with a small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.

Download CodeIgniter from the official website and extract it to your web server directory. Or use Composer:

composer create-project codeigniter4/appstarter project-root

CodeIgniter uses the Model-View-Controller (MVC) pattern to separate application logic from presentation.

Routes define how URLs map to controllers. Configure routes in app/Config/Routes.php:

$routes->get('/', 'Home::index');

Controllers handle requests and return responses. Example:

class Home extends BaseController {
public function index() {
return view('welcome_message');
}
}

Models interact with the database. Example:

class UserModel extends Model {
protected $table = 'users';
}

Views display data to the user. Example:

echo view('welcome_message');

Manage user sessions and cookies easily:

$session = session();
$session->set('user_id', 1);

Helpers are utility functions for common tasks. Load a helper:

helper('url');

CodeIgniter provides error logging and custom error pages.

Upload and manage files using built-in libraries.

Send emails using the Email library.

$email = \Config\Services::email();
$email->setTo('user@example.com');
$email->setSubject('Subject');
$email->setMessage('Message');
$email->send();

Interact with databases using the Query Builder or raw SQL.

$db = \Config\Database::connect();
$query = $db->query('SELECT * FROM users');

Hooks allow you to execute scripts at specific points in the application lifecycle.